[Libreoffice-commits] core.git: sc/inc sc/source

László Németh laszlo.nemeth at collabora.com
Thu Feb 12 14:51:49 PST 2015


 sc/inc/tokenarray.hxx              |    3 +
 sc/source/core/tool/token.cxx      |   72 ++++++++++++++++++++++---------------
 sc/source/filter/excel/excform.cxx |    7 ++-
 3 files changed, 49 insertions(+), 33 deletions(-)

New commits:
commit ba686b9bd2596811141e4028947334f10799c356
Author: László Németh <laszlo.nemeth at collabora.com>
Date:   Thu Feb 12 23:19:32 2015 +0100

    tdf#89281 fix performance regression of XLS import - cleanup
    
    Change-Id: I6d7f279732d9992d584aab96c3a747d6e6130147

diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index d1a4bed..9dc94b9 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -239,7 +239,8 @@ public:
      */
     OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
 
-    bool WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow, bool bQueryNeedWrap = false);
+    void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
+    bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const;
 
 #if DEBUG_FORMULA_COMPILER
     void Dump() const;
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 563b200..b27048a 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3994,27 +3994,17 @@ OUString ScTokenArray::CreateString( sc::TokenStringContext& rCxt, const ScAddre
 
 namespace {
 
-bool wrapAddress( ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow, bool bQueryOnly )
+void wrapAddress( ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow )
 {
-    bool bChanged = false;
     if (rPos.Col() > nMaxCol)
-    {
-        if (!bQueryOnly)
-            rPos.SetCol(rPos.Col() - nMaxCol - 1);
-        bChanged = true;
-    }
+        rPos.SetCol(rPos.Col() - nMaxCol - 1);
     if (rPos.Row() > nMaxRow)
-    {
-        if (!bQueryOnly)
-            rPos.SetRow(rPos.Row() - nMaxRow - 1);
-        bChanged = true;
-    }
-    return bChanged;
+        rPos.SetRow(rPos.Row() - nMaxRow - 1);
 }
 
 }
 
-bool ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow, bool bQueryNeedWrap)
+void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow )
 {
     FormulaToken** p = pCode;
     FormulaToken** pEnd = p + static_cast<size_t>(nLen);
@@ -4027,12 +4017,8 @@ bool ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nM
                 formula::FormulaToken* pToken = *p;
                 ScSingleRefData& rRef = *pToken->GetSingleRef();
                 ScAddress aAbs = rRef.toAbs(rPos);
-                if (wrapAddress(aAbs, nMaxCol, nMaxRow, bQueryNeedWrap))
-                {
-                    if (bQueryNeedWrap)
-                        return true;
-                    rRef.SetAddress(aAbs, rPos);
-                }
+                wrapAddress(aAbs, nMaxCol, nMaxRow);
+                rRef.SetAddress(aAbs, rPos);
             }
             break;
             case svDoubleRef:
@@ -4040,15 +4026,43 @@ bool ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nM
                 formula::FormulaToken* pToken = *p;
                 ScComplexRefData& rRef = *pToken->GetDoubleRef();
                 ScRange aAbs = rRef.toAbs(rPos);
-                bool bChanged = wrapAddress(aAbs.aStart, nMaxCol, nMaxRow, bQueryNeedWrap);
-                bool bChanged2 = wrapAddress(aAbs.aEnd, nMaxCol, nMaxRow, bQueryNeedWrap);
-                if (bChanged || bChanged2)
-                {
-                    if (bQueryNeedWrap)
-                        return true;
-                    aAbs.PutInOrder();
-                    rRef.SetRange(aAbs, rPos);
-                }
+                wrapAddress(aAbs.aStart, nMaxCol, nMaxRow);
+                wrapAddress(aAbs.aEnd, nMaxCol, nMaxRow);
+                aAbs.PutInOrder();
+                rRef.SetRange(aAbs, rPos);
+            }
+            break;
+            default:
+                ;
+        }
+    }
+}
+
+bool ScTokenArray::NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const
+{
+    FormulaToken** p = pCode;
+    FormulaToken** pEnd = p + static_cast<size_t>(nLen);
+    for (; p != pEnd; ++p)
+    {
+        switch ((*p)->GetType())
+        {
+            case svSingleRef:
+            {
+                formula::FormulaToken* pToken = *p;
+                ScSingleRefData& rRef = *pToken->GetSingleRef();
+                ScAddress aAbs = rRef.toAbs(rPos);
+                if (aAbs.Col() > nMaxCol || aAbs.Row() > nMaxRow)
+                   return true;
+            }
+            break;
+            case svDoubleRef:
+            {
+                formula::FormulaToken* pToken = *p;
+                ScComplexRefData& rRef = *pToken->GetDoubleRef();
+                ScRange aAbs = rRef.toAbs(rPos);
+                if (aAbs.aStart.Col() > nMaxCol || aAbs.aStart.Row() > nMaxRow ||
+                    aAbs.aEnd.Col() > nMaxCol || aAbs.aEnd.Row() > nMaxRow)
+                    return true;
             }
             break;
             default:
diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx
index dec9a81..84f9e89 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -122,13 +122,14 @@ void ImportExcel::Formula(
             const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos);
             if (pSharedCode)
             {
-                ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, *pSharedCode);
-                // Do we need to wrap the column or row indices? (tdf#76611)
-                if (pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8, true))
+                ScFormulaCell* pCell;
+                if (pSharedCode->NeedsWrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8))
                 {
                     pCell = new ScFormulaCell(pD, aScPos, pSharedCode->Clone());
                     pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
                 }
+                else
+                    pCell = new ScFormulaCell(pD, aScPos, *pSharedCode);
                 rDoc.getDoc().EnsureTable(aScPos.Tab());
                 rDoc.setFormulaCell(aScPos, pCell);
                 pCell->SetNeedNumberFormat(false);


More information about the Libreoffice-commits mailing list