diff options
author | László Németh <laszlo.nemeth@collabora.com> | 2015-02-13 00:06:32 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-02-13 13:12:47 +0000 |
commit | 76610b00b67cf9c4600caed0f4d75d04e825f9d2 (patch) | |
tree | 296969eaf61e2d6a30356f0f2732e988be941b95 | |
parent | 3f7558360c4805076a1705c204c9e8dba12b7358 (diff) |
tdf#89281 fix performance regression of XLS import
The fix for Bug 76611 caused ~20% performance loss in XLS import.
With optional cloning of ScTokenArray of the shared XLS formulas
depending on the need of address wrapping, it is possible to gain
back near the original performance.
Note: The original patch for Bug 76611 has already got an unit test,
too (see wrapped-refs.xls), and that unit test works with this
improved patch, too.
Cherry picked from master:
ba686b9bd2596811141e4028947334f10799c356 cleanup
b18b5b7edf3d14ef5f0efe53e367f88a423088c4 first commit
Change-Id: Ibfb59d1543ef9c4b8a075d5c4e37f77ab451aaa0
Reviewed-on: https://gerrit.libreoffice.org/14393
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | sc/inc/tokenarray.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 34 | ||||
-rw-r--r-- | sc/source/filter/excel/excform.cxx | 10 |
3 files changed, 43 insertions, 2 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index ad61ef3cdc87..412ecfefe71d 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -239,6 +239,7 @@ public: OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const; 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 ee55b074bd59..43e1963ac1df 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -4035,6 +4035,40 @@ void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nM } } +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: + ; + } + } + return false; +} + #if DEBUG_FORMULA_COMPILER void ScTokenArray::Dump() const diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx index 630997a7d06f..1df8fd980c21 100644 --- a/sc/source/filter/excel/excform.cxx +++ b/sc/source/filter/excel/excform.cxx @@ -124,8 +124,14 @@ void ImportExcel::Formula( const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos); if (pSharedCode) { - ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, pSharedCode->Clone()); - pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8); + 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); |