Kaydet (Commit) ba686b9b authored tarafından László Németh's avatar László Németh

tdf#89281 fix performance regression of XLS import - cleanup

Change-Id: I6d7f279732d9992d584aab96c3a747d6e6130147
üst 359cfa16
......@@ -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;
......
......@@ -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:
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment