Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/1631

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/31/1631/1

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
---
M sc/inc/compiler.hxx
M sc/inc/externalrefmgr.hxx
M sc/source/core/tool/compiler.cxx
3 files changed, 34 insertions(+), 2 deletions(-)



diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index d40d261..10af901 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -331,6 +331,7 @@
     ExtendedErrorDetection  meExtendedErrorDetection;
     bool        mbCloseBrackets;            // whether to close open brackets automatically, 
default TRUE
     bool        mbRewind;                   // whether symbol is to be rewound to some step during 
lexical analysis
+    std::vector<sal_uInt16> maExternalFiles;
 
     bool   NextNewToken(bool bInArray = false);
 
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 3fd3ab5..87693a3 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -679,13 +679,13 @@
      */
     bool containsUnsavedReferences() { return !maUnsavedDocShells.empty(); }
 
+    void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell);
+
 private:
     ScExternalRefManager();
     ScExternalRefManager(const ScExternalRefManager&);
 
     void refreshAllRefCells(sal_uInt16 nFileId);
-
-    void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell);
 
     void fillCellFormat(sal_uLong nFmtIndex, ScExternalRefCache::CellFormat* pFmt) const;
 
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index b827019..b6183ba 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2717,6 +2717,7 @@
             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 @@
             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 @@
     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 @@
     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 @@
     // 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;
 }
 

-- 
To view, visit https://gerrit.libreoffice.org/1631
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I25cf2e08195da17c6c8f7d19c74d744df6e1638e
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Kohei Yoshida <kohei.yoshida@gmail.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.