summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-04 10:19:47 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-02-04 10:22:27 -0500
commit059f43f5756076c7d349e9b7d66e3605a948b508 (patch)
tree910ce1aea341c9b8e10d910658a3964ab4c024df
parent9db3b5585c5fa7fff633672fd32510c4066d035a (diff)
Pre-compile all compiler-ready sheet names to avoid doing it repeatedly.
This reduces the lag after updating range names especially with a large number of range names. Change-Id: Idbfa3b6447b693a566192828e7137b2aeaa0d1f5
-rw-r--r--sc/inc/column.hxx3
-rw-r--r--sc/inc/compiler.hxx8
-rw-r--r--sc/inc/formulacell.hxx6
-rw-r--r--sc/inc/table.hxx3
-rw-r--r--sc/inc/tokenstringcontext.hxx9
-rw-r--r--sc/source/core/data/column2.cxx11
-rw-r--r--sc/source/core/data/documen4.cxx4
-rw-r--r--sc/source/core/data/formulacell.cxx39
-rw-r--r--sc/source/core/data/table4.cxx5
-rw-r--r--sc/source/core/tool/compiler.cxx18
-rw-r--r--sc/source/core/tool/tokenstringcontext.cxx15
11 files changed, 108 insertions, 13 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index c64ea91624b1..7621961af185 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -59,6 +59,7 @@ class DocumentStreamAccess;
class CellValues;
struct RowSpan;
class RowHeightContext;
+struct CompileFormulaContext;
}
@@ -463,7 +464,7 @@ public:
void CompileDBFormula();
void CompileDBFormula( bool bCreateFormulaString );
- void CompileNameFormula( bool bCreateFormulaString );
+ void CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString );
void CompileColRowNameFormula();
sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, rtl_TextEncoding eCharSet ) const;
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index e258532d81cc..4632641353d5 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -78,6 +78,12 @@ class ScRangeData;
class ScExternalRefManager;
class ScTokenArray;
+namespace sc {
+
+struct CompileFormulaContext;
+
+}
+
// constants and data types internal to compiler
/*
@@ -356,6 +362,8 @@ private:
static void InitCharClassEnglish();
public:
+ ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos );
+
ScCompiler( ScDocument* pDocument, const ScAddress&);
ScCompiler( ScDocument* pDocument, const ScAddress&,ScTokenArray& rArr);
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 68c620cd67c8..d96ac8e0e210 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -44,6 +44,7 @@ struct RefUpdateContext;
struct RefUpdateInsertTabContext;
struct RefUpdateDeleteTabContext;
struct RefUpdateMoveTabContext;
+struct CompileFormulaContext;
}
@@ -221,6 +222,9 @@ public:
void Compile(const OUString& rFormula,
bool bNoListening = false,
const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT );
+ void Compile(
+ sc::CompileFormulaContext& rCxt, const OUString& rFormula, bool bNoListening = false );
+
void CompileTokenArray( bool bNoListening = false );
void CompileXML( ScProgress& rProgress ); // compile temporary string tokens
void CalcAfterLoad();
@@ -287,7 +291,7 @@ public:
void SetRunning( bool bVal );
void CompileDBFormula();
void CompileDBFormula( bool bCreateFormulaString );
- void CompileNameFormula( bool bCreateFormulaString );
+ void CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString );
void CompileColRowNameFormula();
ScFormulaCell* GetPrevious() const;
ScFormulaCell* GetNext() const;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 52a6cf6ef8da..1c7cb126baca 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -70,6 +70,7 @@ struct NoteEntry;
class DocumentStreamAccess;
class CellValues;
class RowHeightContext;
+struct CompileFormulaContext;
}
@@ -1013,7 +1014,7 @@ private:
bool TestTabRefAbs(SCTAB nTable) const;
void CompileDBFormula();
void CompileDBFormula( bool bCreateFormulaString );
- void CompileNameFormula( bool bCreateFormulaString );
+ void CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString );
void CompileColRowNameFormula();
void RebuildFormulaGroups();
diff --git a/sc/inc/tokenstringcontext.hxx b/sc/inc/tokenstringcontext.hxx
index 85b61f77b13d..fcc7eae42acf 100644
--- a/sc/inc/tokenstringcontext.hxx
+++ b/sc/inc/tokenstringcontext.hxx
@@ -46,6 +46,15 @@ struct SC_DLLPUBLIC TokenStringContext
TokenStringContext( const ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram );
};
+struct CompileFormulaContext
+{
+ ScDocument* mpDoc;
+ formula::FormulaGrammar::Grammar meGram;
+ std::vector<OUString> maTabNames;
+
+ CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram );
+};
+
}
#endif
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 7a58377ec683..4ab6d17edc2a 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -3218,15 +3218,16 @@ public:
class CompileNameFormulaHandler
{
+ sc::CompileFormulaContext& mrCxt;
bool mbCreateFormulaString;
public:
- CompileNameFormulaHandler(bool bCreateFormulaString) :
- mbCreateFormulaString(bCreateFormulaString) {}
+ CompileNameFormulaHandler( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString) :
+ mrCxt(rCxt), mbCreateFormulaString(bCreateFormulaString) {}
void operator() (size_t, ScFormulaCell* p)
{
- p->CompileNameFormula(mbCreateFormulaString);
+ p->CompileNameFormula(mrCxt, mbCreateFormulaString);
}
};
@@ -3254,9 +3255,9 @@ void ScColumn::CompileDBFormula( bool bCreateFormulaString )
RegroupFormulaCells();
}
-void ScColumn::CompileNameFormula( bool bCreateFormulaString )
+void ScColumn::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString )
{
- CompileNameFormulaHandler aFunc(bCreateFormulaString);
+ CompileNameFormulaHandler aFunc(rCxt, bCreateFormulaString);
sc::ProcessFormula(maCells, aFunc);
}
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 23be5e520cd7..c3d7a4341fa1 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -44,6 +44,7 @@
#include "formulacell.hxx"
#include "tokenarray.hxx"
#include "scmatrix.hxx"
+#include <tokenstringcontext.hxx>
using namespace formula;
@@ -558,11 +559,12 @@ void ScDocument::CompileDBFormula( bool bCreateFormulaString )
void ScDocument::CompileNameFormula( bool bCreateFormulaString )
{
+ sc::CompileFormulaContext aCxt(this, eGrammar);
TableContainer::iterator it = maTabs.begin();
for (;it != maTabs.end(); ++it)
{
if (*it)
- (*it)->CompileNameFormula( bCreateFormulaString );
+ (*it)->CompileNameFormula(aCxt, bCreateFormulaString);
}
}
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index ca466a53b877..aee151745350 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -939,6 +939,40 @@ void ScFormulaCell::Compile( const OUString& rFormula, bool bNoListening,
pDocument->PutInFormulaTree( this );
}
+void ScFormulaCell::Compile(
+ sc::CompileFormulaContext& rCxt, const OUString& rFormula, bool bNoListening )
+{
+ if ( pDocument->IsClipOrUndo() )
+ return;
+ bool bWasInFormulaTree = pDocument->IsInFormulaTree( this );
+ if ( bWasInFormulaTree )
+ pDocument->RemoveFromFormulaTree( this );
+ // pCode may not deleted for queries, but must be empty
+ if ( pCode )
+ pCode->Clear();
+ ScTokenArray* pCodeOld = pCode;
+ ScCompiler aComp(rCxt, aPos);
+ pCode = aComp.CompileString( rFormula );
+ if ( pCodeOld )
+ delete pCodeOld;
+ if( !pCode->GetCodeError() )
+ {
+ if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() && rFormula == aResult.GetHybridFormula() )
+ { // not recursive CompileTokenArray/Compile/CompileTokenArray
+ if ( rFormula[0] == '=' )
+ pCode->AddBad( rFormula.copy(1) );
+ else
+ pCode->AddBad( rFormula );
+ }
+ bCompile = true;
+ CompileTokenArray( bNoListening );
+ }
+ else
+ bChanged = true;
+
+ if ( bWasInFormulaTree )
+ pDocument->PutInFormulaTree( this );
+}
void ScFormulaCell::CompileTokenArray( bool bNoListening )
{
@@ -3278,7 +3312,7 @@ void ScFormulaCell::CompileDBFormula( bool bCreateFormulaString )
}
}
-void ScFormulaCell::CompileNameFormula( bool bCreateFormulaString )
+void ScFormulaCell::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString )
{
// Two phases must be called after each other
// 1. Formula String with old generated names
@@ -3319,7 +3353,8 @@ void ScFormulaCell::CompileNameFormula( bool bCreateFormulaString )
}
else if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() )
{
- Compile( aResult.GetHybridFormula(), false, eTempGrammar );
+ assert(rCxt.meGram == eTempGrammar);
+ Compile(rCxt, aResult.GetHybridFormula(), false);
aResult.SetToken( NULL);
SetDirty();
}
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 88d1f6810822..91b9187fce58 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -2186,9 +2186,10 @@ void ScTable::CompileDBFormula( bool bCreateFormulaString )
for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileDBFormula( bCreateFormulaString );
}
-void ScTable::CompileNameFormula( bool bCreateFormulaString )
+void ScTable::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString )
{
- for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileNameFormula( bCreateFormulaString );
+ for (SCCOL i = 0; i <= MAXCOL; ++i)
+ aCol[i].CompileNameFormula(rCxt, bCreateFormulaString);
}
void ScTable::CompileColRowNameFormula()
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index d5ea15621dc2..ce0f4279fa03 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -67,6 +67,7 @@
#include "formulaparserpool.hxx"
#include "tokenarray.hxx"
#include "scmatrix.hxx"
+#include <tokenstringcontext.hxx>
using namespace formula;
using namespace ::com::sun::star;
@@ -1539,6 +1540,23 @@ ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos,ScTokenArra
}
}
+ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos ) :
+ pDoc(rCxt.mpDoc),
+ 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.maTabNames)
+{
+ nMaxTab = pDoc ? pDoc->GetTableCount() - 1 : 0;
+ SetGrammar(rCxt.meGram);
+}
+
ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos)
:
pDoc( pDocument ),
diff --git a/sc/source/core/tool/tokenstringcontext.cxx b/sc/source/core/tool/tokenstringcontext.cxx
index a68ae759299a..0273a216462f 100644
--- a/sc/source/core/tool/tokenstringcontext.cxx
+++ b/sc/source/core/tool/tokenstringcontext.cxx
@@ -105,6 +105,21 @@ TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::Formula
}
}
+CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) :
+ mpDoc(pDoc), meGram(eGram)
+{
+ if (!pDoc)
+ return;
+
+ // Fetch all sheet names.
+ maTabNames = pDoc->GetAllTableNames();
+ {
+ std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end();
+ for (; it != itEnd; ++it)
+ ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(eGram));
+ }
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */