[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter' - 2 commits - sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Fri Jul 12 08:40:56 PDT 2013
sc/source/core/tool/formulagroup.cxx | 37 +++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
New commits:
commit 6c320856290e17cdad6c3fb75c63ec63bb247b33
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jul 12 11:40:54 2013 -0400
Cache select converted tokens to avoid unnecessary token duplication.
Change-Id: I3a63d5cbbc1cdc37d681ffd41ec22ff65e56cc0d
diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx
index 6573d15..4ac4b6b 100644
--- a/sc/source/core/tool/formulagroup.cxx
+++ b/sc/source/core/tool/formulagroup.cxx
@@ -19,6 +19,7 @@
#include "formula/vectortoken.hxx"
#include <vector>
+#include <boost/unordered_map.hpp>
#define USE_DUMMY_INTERPRETER 1
@@ -37,6 +38,8 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres
const ScFormulaCellGroupRef& xGroup,
ScTokenArray& rCode)
{
+ typedef boost::unordered_map<const formula::FormulaToken*, formula::FormulaTokenRef> CachedTokensType;
+
// Decompose the group into individual cells and calculate them individually.
// The caller must ensure that the top position is the start position of
@@ -45,11 +48,21 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres
ScAddress aTmpPos = rTopPos;
std::vector<double> aResults;
aResults.reserve(xGroup->mnLength);
+ CachedTokensType aCachedTokens;
+
for (SCROW i = 0; i < xGroup->mnLength; ++i, aTmpPos.IncRow())
{
ScTokenArray aCode2;
for (const formula::FormulaToken* p = rCode.First(); p; p = rCode.Next())
{
+ CachedTokensType::iterator it = aCachedTokens.find(p);
+ if (it != aCachedTokens.end())
+ {
+ // This token is cached. Use the cached one.
+ aCode2.AddToken(*it->second);
+ continue;
+ }
+
switch (p->GetType())
{
case formula::svSingleVectorRef:
@@ -77,8 +90,18 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres
pMat->PutDouble(pArray, nRowSize, nCol, 0);
}
- ScMatrixToken aTok(pMat);
- aCode2.AddToken(aTok);
+ if (p2->IsStartFixed() && p2->IsEndFixed())
+ {
+ // Cached the converted token for absolute range referene.
+ formula::FormulaTokenRef xTok(new ScMatrixToken(pMat));
+ aCachedTokens.insert(CachedTokensType::value_type(p, xTok));
+ aCode2.AddToken(*xTok);
+ }
+ else
+ {
+ ScMatrixToken aTok(pMat);
+ aCode2.AddToken(aTok);
+ }
}
break;
default:
commit 644fdbdc7ece20fb5d2b8f64195ab6faed2d4230
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Fri Jul 12 11:09:38 2013 -0400
Set an array of doubles in one step, rather than individually in loops.
The latter is massively slow, apparently.
Change-Id: I689643330e1b04eff7d9665de5d6e423906517e1
diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx
index 5a23511..6573d15 100644
--- a/sc/source/core/tool/formulagroup.cxx
+++ b/sc/source/core/tool/formulagroup.cxx
@@ -73,14 +73,8 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres
for (size_t nCol = 0; nCol < nColSize; ++nCol)
{
const double* pArray = rArrays[nCol];
- for (size_t nRow = 0; nRow < nRowSize; ++nRow)
- {
- if (nRowStart + nRow < p2->GetArrayLength())
- {
- double fVal = pArray[nRowStart+nRow];
- pMat->PutDouble(fVal, nCol, nRow);
- }
- }
+ pArray += nRowStart;
+ pMat->PutDouble(pArray, nRowSize, nCol, 0);
}
ScMatrixToken aTok(pMat);
More information about the Libreoffice-commits
mailing list