[Libreoffice-commits] core.git: sc/inc sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Tue Feb 4 07:18:02 PST 2014
sc/inc/column.hxx | 3 +-
sc/inc/compiler.hxx | 8 +++++
sc/inc/formulacell.hxx | 6 +++-
sc/inc/table.hxx | 3 +-
sc/inc/tokenstringcontext.hxx | 9 ++++++
sc/source/core/data/column2.cxx | 11 ++++----
sc/source/core/data/documen4.cxx | 4 ++
sc/source/core/data/formulacell.cxx | 39 +++++++++++++++++++++++++++--
sc/source/core/data/table4.cxx | 5 ++-
sc/source/core/tool/compiler.cxx | 18 +++++++++++++
sc/source/core/tool/tokenstringcontext.cxx | 15 +++++++++++
11 files changed, 108 insertions(+), 13 deletions(-)
New commits:
commit 059f43f5756076c7d349e9b7d66e3605a948b508
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Tue Feb 4 10:19:47 2014 -0500
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
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index c64ea91..7621961 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 e258532..4632641 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 68c620c..d96ac8e 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 52a6cf6..1c7cb12 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 85b61f7..fcc7eae 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 7a58377..4ab6d17 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 23be5e5..c3d7a43 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 ca466a5..aee1517 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 88d1f68..91b9187 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 d5ea156..ce0f427 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 a68ae75..0273a21 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: */
More information about the Libreoffice-commits
mailing list