summaryrefslogtreecommitdiff
path: root/sc/source/core/tool
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-01-10 12:02:07 -0500
committerNoel Power <noel.power@suse.com>2013-01-11 11:39:20 +0000
commit260f1b19ce7340b02fce5aea948caa61ee128f44 (patch)
treea129111926cee53851b4bd5951216e87f1e703e2 /sc/source/core/tool
parent5a0dc1d1fdeac4b06b39ea616374d3f81b6be8a9 (diff)
fdo#58531: Register cells with external references at compile time.
In the old code, we would do this during interpretation. But we need to move that to the compilation to make this work properly without full recalculation during ods import. For 4.0, we'll just add calls to insertRefCells in ScCompiler. On master we should remove these calls from the old places to avoid duplicate calls. Duplicate calls for the same external file ID - cell address pair will not hurt; it just adds more overhead. Change-Id: I25cf2e08195da17c6c8f7d19c74d744df6e1638e Reviewed-on: https://gerrit.libreoffice.org/1631 Reviewed-by: Noel Power <noel.power@suse.com> Tested-by: Noel Power <noel.power@suse.com>
Diffstat (limited to 'sc/source/core/tool')
-rw-r--r--sc/source/core/tool/compiler.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index b82701997fff..b6183ba58483 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2717,6 +2717,7 @@ bool ScCompiler::IsDoubleReference( const String& rName )
const OUString* pRealTab = pRefMgr->getRealTableName(aExtInfo.mnFileId, aExtInfo.maTabName);
aToken.SetExternalDoubleRef(
aExtInfo.mnFileId, pRealTab ? *pRealTab : aExtInfo.maTabName, aRef);
+ maExternalFiles.push_back(aExtInfo.mnFileId);
}
else
{
@@ -2765,6 +2766,7 @@ bool ScCompiler::IsSingleReference( const String& rName )
const OUString* pRealTab = pRefMgr->getRealTableName(aExtInfo.mnFileId, aExtInfo.maTabName);
aToken.SetExternalSingleRef(
aExtInfo.mnFileId, pRealTab ? *pRealTab : aExtInfo.maTabName, aRef);
+ maExternalFiles.push_back(aExtInfo.mnFileId);
}
else
aToken.SetSingleReference(aRef);
@@ -2973,6 +2975,7 @@ bool ScCompiler::IsExternalNamedRange( const String& rSymbol )
const OUString* pRealName = pRefMgr->getRealRangeName(nFileId, aName);
aToken.SetExternalName(nFileId, pRealName ? *pRealName : OUString(aTmp));
pRawToken = aToken.Clone();
+ maExternalFiles.push_back(nFileId);
return true;
}
@@ -3737,6 +3740,24 @@ void ScCompiler::CreateStringFromXMLTokenArray( rtl::OUString& rFormula, rtl::OU
rFormulaNmsp = aFormulaNmsp;
}
+namespace {
+
+class ExternalFileInserter : std::unary_function<sal_uInt16, void>
+{
+ ScAddress maPos;
+ ScExternalRefManager& mrRefMgr;
+public:
+ ExternalFileInserter(const ScAddress& rPos, ScExternalRefManager& rRefMgr) :
+ maPos(rPos), mrRefMgr(rRefMgr) {}
+
+ void operator() (sal_uInt16 nFileId) const
+ {
+ mrRefMgr.insertRefCell(nFileId, maPos);
+ }
+};
+
+}
+
ScTokenArray* ScCompiler::CompileString( const String& rFormula )
{
OSL_ENSURE( meGrammar != FormulaGrammar::GRAM_EXTERNAL, "ScCompiler::CompileString - unexpected grammar GRAM_EXTERNAL" );
@@ -3943,6 +3964,16 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula )
// remember pArr, in case a subsequent CompileTokenArray() is executed.
ScTokenArray* pNew = new ScTokenArray( aArr );
pArr = pNew;
+
+ if (!maExternalFiles.empty())
+ {
+ // Remove duplicates, and register all external files found in this cell.
+ std::sort(maExternalFiles.begin(), maExternalFiles.end());
+ std::vector<sal_uInt16>::iterator itEnd = std::unique(maExternalFiles.begin(), maExternalFiles.end());
+ std::for_each(maExternalFiles.begin(), itEnd, ExternalFileInserter(aPos, *pDoc->GetExternalRefManager()));
+ maExternalFiles.erase(itEnd, maExternalFiles.end());
+ }
+
return pNew;
}