summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-09-04 15:35:57 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-09-04 22:00:41 +0200
commit73c5ff374629f3e6bb92fcd52ab8597d52c67af9 (patch)
tree0f71377b81f9f289a0658a819d8ee8b777164475
parentb68e82b17998ff7ce7e5b08419ecad6b54153566 (diff)
inline ScTokenArray into ScFormulaCellGroup
Change-Id: I3a12566141b3243142c5e30381ac5eb3ba9c493a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121645 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sc/inc/formulacell.hxx7
-rw-r--r--sc/source/core/data/column4.cxx2
-rw-r--r--sc/source/core/data/formulacell.cxx18
-rw-r--r--sc/source/core/tool/sharedformula.cxx6
4 files changed, 18 insertions, 15 deletions
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index b685bbbf7b35..9ad2ba7b16f7 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -21,6 +21,7 @@
#include <map>
#include <memory>
+#include <optional>
#include <formula/tokenarray.hxx>
#include <formula/errorcodes.hxx>
@@ -32,6 +33,7 @@
#include "docoptio.hxx"
#include "formulalogger.hxx"
#include "formularesult.hxx"
+#include "tokenarray.hxx"
namespace sc {
@@ -49,7 +51,6 @@ class UpdatedRangeNames;
class ScFormulaCell;
class ScProgress;
-class ScTokenArray;
enum class SvNumFormatType : sal_Int16;
struct AreaListenerKey
@@ -73,7 +74,7 @@ public:
mutable size_t mnRefCount;
- std::unique_ptr<ScTokenArray> mpCode;
+ std::optional<ScTokenArray> mpCode;
ScFormulaCell *mpTopCell;
SCROW mnLength; // How many of these do we have ?
sal_Int32 mnWeight;
@@ -90,7 +91,7 @@ public:
~ScFormulaCellGroup();
void setCode( const ScTokenArray& rCode );
- void setCode( std::unique_ptr<ScTokenArray> pCode );
+ void setCode( std::optional<ScTokenArray> pCode );
void compileCode(
ScDocument& rDoc, const ScAddress& rPos, formula::FormulaGrammar::Grammar eGram );
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index b490c557dfe0..f7f7d2a294da 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -927,7 +927,7 @@ public:
std::unique_ptr<ScTokenArray> pNewCode = aComp.CompileString(aFormula);
ScFormulaCellGroupRef xGroup = pTop->GetCellGroup();
assert(xGroup);
- xGroup->setCode(std::move(pNewCode));
+ xGroup->setCode(std::move(*pNewCode));
xGroup->compileCode(mrDoc, pTop->aPos, mrDoc.GetGrammar());
// Propagate the new token array to all formula cells in the group.
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index e60768aadb99..1600a1248141 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -521,12 +521,12 @@ ScFormulaCellGroup::~ScFormulaCellGroup()
void ScFormulaCellGroup::setCode( const ScTokenArray& rCode )
{
- mpCode = rCode.Clone();
+ mpCode = rCode.CloneValue();
mbInvariant = mpCode->IsInvariant();
mpCode->GenHash();
}
-void ScFormulaCellGroup::setCode( std::unique_ptr<ScTokenArray> pCode )
+void ScFormulaCellGroup::setCode( std::optional<ScTokenArray> pCode )
{
mpCode = std::move(pCode); // takes ownership of the token array.
mpCode->Finalize(); // Reduce memory usage if needed.
@@ -771,7 +771,7 @@ ScFormulaCell::ScFormulaCell(
nSeenInIteration(0),
nFormatType(xGroup->mnFormatType),
eTempGrammar( eGrammar),
- pCode(xGroup->mpCode ? xGroup->mpCode.get() : new ScTokenArray(rDoc)),
+ pCode(xGroup->mpCode ? &*xGroup->mpCode : new ScTokenArray(rDoc)),
rDocument( rDoc ),
pPrevious(nullptr),
pNext(nullptr),
@@ -3990,7 +3990,9 @@ ScFormulaCellGroupRef ScFormulaCell::CreateCellGroup( SCROW nLen, bool bInvarian
mxGroup->mpTopCell = this;
mxGroup->mbInvariant = bInvariant;
mxGroup->mnLength = nLen;
- mxGroup->mpCode.reset(pCode); // Move this to the shared location.
+ mxGroup->mpCode = std::move(*pCode); // Move this to the shared location.
+ delete pCode;
+ pCode = &*mxGroup->mpCode;
return mxGroup;
}
@@ -4012,7 +4014,7 @@ void ScFormulaCell::SetCellGroup( const ScFormulaCellGroupRef &xRef )
delete pCode;
mxGroup = xRef;
- pCode = mxGroup->mpCode.get();
+ pCode = &*mxGroup->mpCode;
mxGroup->mnWeight = 0; // invalidate
}
@@ -5480,12 +5482,12 @@ sal_Int32 ScFormulaCell::GetWeight() const
ScTokenArray* ScFormulaCell::GetSharedCode()
{
- return mxGroup ? mxGroup->mpCode.get() : nullptr;
+ return mxGroup ? &*mxGroup->mpCode : nullptr;
}
const ScTokenArray* ScFormulaCell::GetSharedCode() const
{
- return mxGroup ? mxGroup->mpCode.get() : nullptr;
+ return mxGroup ? &*mxGroup->mpCode : nullptr;
}
void ScFormulaCell::SyncSharedCode()
@@ -5494,7 +5496,7 @@ void ScFormulaCell::SyncSharedCode()
// Not a shared formula cell.
return;
- pCode = mxGroup->mpCode.get();
+ pCode = &*mxGroup->mpCode;
}
#if DUMP_COLUMN_STORAGE
diff --git a/sc/source/core/tool/sharedformula.cxx b/sc/source/core/tool/sharedformula.cxx
index 4617239fe91d..167bd951e226 100644
--- a/sc/source/core/tool/sharedformula.cxx
+++ b/sc/source/core/tool/sharedformula.cxx
@@ -66,7 +66,7 @@ bool SharedFormulaUtil::splitFormulaCellGroup(const CellStoreType::position_type
xGroup2->mbInvariant = xGroup->mbInvariant;
xGroup2->mpTopCell = &rTop;
xGroup2->mnLength = nLength2;
- xGroup2->mpCode = xGroup->mpCode->Clone();
+ xGroup2->mpCode = xGroup->mpCode->CloneValue();
}
xGroup->mnLength = nRow - xGroup->mpTopCell->aPos.Row();
@@ -322,7 +322,7 @@ void SharedFormulaUtil::unshareFormulaCell(const CellStoreType::position_type& a
xGroup2->mpTopCell = &rNext;
xGroup2->mnLength = nLength2;
xGroup2->mbInvariant = xGroup->mbInvariant;
- xGroup2->mpCode = xGroup->mpCode->Clone();
+ xGroup2->mpCode = xGroup->mpCode->CloneValue();
#if DEBUG_COLUMN_STORAGE
if (xGroup2->mpTopCell->aPos.Row() + size_t(xGroup2->mnLength) > it->position + it->size)
{
@@ -392,7 +392,7 @@ void SharedFormulaUtil::startListeningAsGroup( sc::StartListeningContext& rCxt,
rDoc.SetDetectiveDirty(true);
ScFormulaCellGroupRef xGroup = rTopCell.GetCellGroup();
- const ScTokenArray* pCode = xGroup->mpCode.get();
+ const ScTokenArray* pCode = xGroup->mpCode ? &*xGroup->mpCode : nullptr;
assert(pCode == rTopCell.GetCode());
if (pCode->IsRecalcModeAlways())
{