summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2014-12-19 17:51:53 +0200
committerTor Lillqvist <tml@collabora.com>2014-12-19 23:14:08 +0200
commitcc4dbc0c4613b169045341d1f02bc4c47a407fa0 (patch)
treea52df58883de578fd084a13114bec60623ba788e /sc
parent10d1eb5e933a6e37411e618cd89fa8c0a72b941b (diff)
Check number of cells referenced by group instead of group size
It's more relevant when deciding whether to use OpenCL or not. Note that we won't use OpenCL for a single formula cell, no matter how large a calculation it invokes (like =SUM(A1:A1000000), for instance), as a single cell is not a group. Change-Id: I66b03c197431c2b4cef96f46b010d99d3e0624fc
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/formulacell.hxx4
-rw-r--r--sc/inc/tokenarray.hxx3
-rw-r--r--sc/source/core/data/formulacell.cxx9
-rw-r--r--sc/source/core/tool/token.cxx27
4 files changed, 42 insertions, 1 deletions
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 0ed021f6b756..899d3b70b3cc 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -410,6 +410,10 @@ public:
bool IsSharedTop() const;
SCROW GetSharedTopRow() const;
SCROW GetSharedLength() const;
+
+ // An estimate of the number of cells referenced by the formula
+ sal_Int32 GetWeight() const;
+
ScTokenArray* GetSharedCode();
const ScTokenArray* GetSharedCode() const;
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index 5d6593d6f8f1..ab1e9419042b 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -60,6 +60,9 @@ public:
virtual ~ScTokenArray();
ScTokenArray* Clone() const; /// True copy!
+ // An estimate of the number of cells referenced by the token array
+ sal_Int32 GetWeight() const;
+
void GenHash();
size_t GetHash() const { return mnHashValue;}
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index a7f48134e87f..5c6511f2273f 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -3752,7 +3752,7 @@ bool ScFormulaCell::InterpretFormulaGroup()
if (mxGroup->meCalcState == sc::GroupCalcDisabled)
return false;
- if (GetSharedLength() < ScInterpreter::GetGlobalConfig().mnOpenCLMinimumFormulaGroupSize)
+ if (GetWeight() < ScInterpreter::GetGlobalConfig().mnOpenCLMinimumFormulaGroupSize)
{
mxGroup->meCalcState = sc::GroupCalcDisabled;
return false;
@@ -4130,6 +4130,13 @@ SCROW ScFormulaCell::GetSharedLength() const
return mxGroup ? mxGroup->mnLength : 0;
}
+sal_Int32 ScFormulaCell::GetWeight() const
+{
+ if (!mxGroup)
+ return pCode->GetWeight();
+ return GetSharedLength() * GetSharedCode()->GetWeight();
+}
+
ScTokenArray* ScFormulaCell::GetSharedCode()
{
return mxGroup ? mxGroup->mpCode : NULL;
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index e52d5817bef2..a4f247317b08 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1413,6 +1413,33 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, const ScAddress& rPos, boo
return bIs;
}
+sal_Int32 ScTokenArray::GetWeight() const
+{
+ sal_Int32 result(0);
+
+ FormulaToken** p = pCode;
+ FormulaToken** pEnd = p + static_cast<size_t>(nLen);
+ for (; p != pEnd; ++p)
+ {
+ switch ((*p)->GetType())
+ {
+ case svDoubleRef :
+ case svExternalDoubleRef:
+ {
+ const ScComplexRefData& rRef = *(*p)->GetDoubleRef();
+ result += ( (rRef.Ref2.Row() - rRef.Ref1.Row() + 1) * (rRef.Ref2.Col() - rRef.Ref1.Col() + 1) );
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ // Just print out the this pointer. It turns out to be quite complicated to get
+ // a symbolic printout of the ScTokenArray here.
+ SAL_INFO("sc.token", "GetWeight(" << this << "): " << result);
+ return result;
+}
+
namespace {
// we want to compare for similar not identical formulae