diff options
author | Tor Lillqvist <tml@collabora.com> | 2017-08-29 22:11:06 +0300 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.co.uk> | 2017-11-21 13:49:49 +0530 |
commit | 0772d773ecbf97293783c55671db60241e97019e (patch) | |
tree | 1d2030ecb812fece860a421702f4369cc417eeb2 | |
parent | 157414d6971956ba6549e2f9d8c0436f650c76d9 (diff) |
Make formula group weight take number of cells referenced into account
And not just the number of rows in the group. This means that even
relatively short formula groups that calculate over large ranges of
cells will be eligible for parallelized calculation. The weight of a
formula group is the number of rows in the group times the weight of
the formula.
The weight of a formula is for now the number of cells referenced by
all cell ranges in the formula, divided by 10. For instance, the
weight of SUM(A1:B100) would be 20. If no cell ranges are used, the
formula's weight is one.
Change-Id: Ib77e403961d8f487d580eea6b901fa4f5e4102b0
-rw-r--r-- | sc/inc/tokenarray.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 13 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 33 |
3 files changed, 42 insertions, 6 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 317f7d138361..294794f959e0 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -256,6 +256,8 @@ public: void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ); bool NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow ) const; + sal_Int32 GetWeight() const; + #if DEBUG_FORMULA_COMPILER void Dump() const; #endif diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 622a012d29a2..9a31f479f3b5 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -4788,13 +4788,14 @@ SCROW ScFormulaCell::GetSharedLength() const sal_Int32 ScFormulaCell::GetWeight() const { -#if 0 if (!mxGroup) - return pCode->GetWeight(); - return GetSharedLength() * GetSharedCode()->GetWeight(); -#else - return GetSharedLength(); -#endif + return 1; + double nSharedCodeWeight = GetSharedCode()->GetWeight(); + double nResult = nSharedCodeWeight * GetSharedLength(); + if (nResult < SAL_MAX_INT32) + return nResult; + else + return SAL_MAX_INT32; } ScTokenArray* ScFormulaCell::GetSharedCode() diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 0cf7c872f031..6ca476fff188 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -5243,6 +5243,39 @@ bool ScTokenArray::NeedsWrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCR return false; } +sal_Int32 ScTokenArray::GetWeight() const +{ + sal_Int32 nResult = 0; + for (auto i = 0; i < nRPN; ++i) + { + switch ((*pRPN[i]).GetType()) + { + case svDoubleRef: + { + const auto pComplexRef = (*pRPN[i]).GetDoubleRef(); + + // Number of cells referenced divided by 10. + const double nNumCellsTerm = + (1 + (pComplexRef->Ref2.Row() - pComplexRef->Ref1.Row())) * + (1 + (pComplexRef->Ref2.Col() - pComplexRef->Ref1.Col())) / 10.; + + if (nNumCellsTerm + nResult < SAL_MAX_INT32) + nResult += nNumCellsTerm; + else + nResult = SAL_MAX_INT32; + } + break; + default: + ; + } + } + + if (nResult == 0) + nResult = 1; + + return nResult; +} + #if DEBUG_FORMULA_COMPILER void ScTokenArray::Dump() const |