diff options
author | László Németh <laszlo.nemeth@collabora.com> | 2015-02-12 23:19:32 +0100 |
---|---|---|
committer | László Németh <laszlo.nemeth@collabora.com> | 2015-02-12 23:19:32 +0100 |
commit | ba686b9bd2596811141e4028947334f10799c356 (patch) | |
tree | d65d3e559f68db03ae9f76d028b93f248cd08e0d /sc | |
parent | 359cfa160b02aef5bb9f792a4650f18279f9eee8 (diff) |
tdf#89281 fix performance regression of XLS import - cleanup
Change-Id: I6d7f279732d9992d584aab96c3a747d6e6130147
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/tokenarray.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 72 | ||||
-rw-r--r-- | sc/source/filter/excel/excform.cxx | 7 |
3 files changed, 49 insertions, 33 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index d1a4bed9d879..9dc94b9a9c4a 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 563b2007b28d..b27048a4c029 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 dec9a8165e32..84f9e8975cb8 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); |