diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-04 10:19:47 -0500 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2014-02-06 14:37:10 +0000 |
commit | 99a835ca644d69241cba9d7e4c4a315a4a3ea652 (patch) | |
tree | 6f5a05825df489ec953490772bbaeda81e30e63b /sc/source/core/tool | |
parent | 8e8827a2d092810394c819c536d48b74080abce8 (diff) |
fdo#74516: Avoid excessive building of escaped sheet names.
The old code would build an array of escaped sheet names for all sheets
on evevery invokation of ScCompiler, which unfortunately slowed down these
"compile all formula cells" type methods, such as CompileAll(), CompileXML()
etc. Let's avoid that and build or re-build the list only when necessary.
Conflicts:
sc/inc/column.hxx
sc/inc/table.hxx
sc/source/core/data/document.cxx
sc/source/core/tool/compiler.cxx
Change-Id: Iabf7c2374b728b6701da3aae7835cca2157f6c96
Reviewed-on: https://gerrit.libreoffice.org/7861
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Diffstat (limited to 'sc/source/core/tool')
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 36 | ||||
-rw-r--r-- | sc/source/core/tool/rangenam.cxx | 11 | ||||
-rw-r--r-- | sc/source/core/tool/tokenstringcontext.cxx | 43 |
3 files changed, 85 insertions, 5 deletions
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index dcb676e4a001..4a1bbd723570 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -68,6 +68,7 @@ #include "formulaparserpool.hxx" #include "tokenarray.hxx" #include "scmatrix.hxx" +#include <tokenstringcontext.hxx> using namespace formula; using namespace ::com::sun::star; @@ -1529,6 +1530,24 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL static const ConventionXL_R1C1 ConvXL_R1C1; const ScCompiler::Convention * const ScCompiler::pConvXL_R1C1 = &ConvXL_R1C1; +ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos, ScTokenArray& rArr ) : + FormulaCompiler(rArr), + pDoc(rCxt.getDoc()), + aPos(rPos), + mpFormatter(pDoc->GetFormatTable()), + pCharClass(ScGlobal::pCharClass), + mnPredetectedReference(0), + mnRangeOpPosInSymbol(-1), + pConv(GetRefConvention(FormulaGrammar::CONV_OOO)), + meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE), + mbCloseBrackets(true), + mbRewind(false), + maTabNames(rCxt.getTabNames()) +{ + nMaxTab = pDoc ? pDoc->GetTableCount() - 1 : 0; + SetGrammar(rCxt.getGrammar()); +} + ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos,ScTokenArray& rArr) : FormulaCompiler(rArr), pDoc( pDocument ), @@ -1555,6 +1574,23 @@ ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos,ScTokenArra } } +ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos ) : + pDoc(rCxt.getDoc()), + aPos(rPos), + mpFormatter(pDoc ? pDoc->GetFormatTable() : NULL), + pCharClass(ScGlobal::pCharClass), + mnPredetectedReference(0), + mnRangeOpPosInSymbol(-1), + pConv(GetRefConvention(FormulaGrammar::CONV_OOO)), + meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE), + mbCloseBrackets(true), + mbRewind(false), + maTabNames(rCxt.getTabNames()) +{ + nMaxTab = pDoc ? pDoc->GetTableCount() - 1 : 0; + SetGrammar(rCxt.getGrammar()); +} + ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos) : pDoc( pDocument ), diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index 6130c614a138..5d88ee8c6959 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -34,6 +34,7 @@ #include "refupdat.hxx" #include "document.hxx" #include "refupdatecontext.hxx" +#include <tokenstringcontext.hxx> #include "formula/errorcodes.hxx" @@ -181,14 +182,14 @@ void ScRangeData::CompileRangeData( const OUString& rSymbol, bool bSetError ) } } -void ScRangeData::CompileUnresolvedXML() +void ScRangeData::CompileUnresolvedXML( sc::CompileFormulaContext& rCxt ) { if (pCode->GetCodeError() == errNoName) { // Reconstruct the symbol/formula and then recompile. OUString aSymbol; - ScCompiler aComp( pDoc, aPos, *pCode); - aComp.SetGrammar( eTempGrammar); + rCxt.setGrammar(eTempGrammar); + ScCompiler aComp(rCxt, aPos, *pCode); aComp.CreateStringFromTokenArray( aSymbol); // Don't let the compiler set an error for unknown names on final // compile, errors are handled by the interpreter thereafter. @@ -764,11 +765,11 @@ void ScRangeName::UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY) itr->second->UpdateGrow(rArea, nGrowX, nGrowY); } -void ScRangeName::CompileUnresolvedXML() +void ScRangeName::CompileUnresolvedXML( sc::CompileFormulaContext& rCxt ) { DataType::iterator itr = maData.begin(), itrEnd = maData.end(); for (; itr != itrEnd; ++itr) - itr->second->CompileUnresolvedXML(); + itr->second->CompileUnresolvedXML(rCxt); } ScRangeName::const_iterator ScRangeName::begin() const diff --git a/sc/source/core/tool/tokenstringcontext.cxx b/sc/source/core/tool/tokenstringcontext.cxx index a68ae759299a..203d36aaf3e8 100644 --- a/sc/source/core/tool/tokenstringcontext.cxx +++ b/sc/source/core/tool/tokenstringcontext.cxx @@ -105,6 +105,49 @@ TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::Formula } } +CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc ) : + mpDoc(pDoc), meGram(pDoc->GetGrammar()) +{ + if (!pDoc) + return; + + updateTabNames(); +} + +void CompileFormulaContext::updateTabNames() +{ + // Fetch all sheet names. + maTabNames = mpDoc->GetAllTableNames(); + { + std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end(); + for (; it != itEnd; ++it) + ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(meGram)); + } +} + +formula::FormulaGrammar::Grammar CompileFormulaContext::getGrammar() const +{ + return meGram; +} + +void CompileFormulaContext::setGrammar( formula::FormulaGrammar::Grammar eGram ) +{ + bool bUpdate = (meGram != eGram); + meGram = eGram; + if (bUpdate) + updateTabNames(); +} + +const std::vector<OUString>& CompileFormulaContext::getTabNames() const +{ + return maTabNames; +} + +ScDocument* CompileFormulaContext::getDoc() +{ + return mpDoc; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |