summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-08-11 16:17:50 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-11 21:54:08 +0200
commit4cb85b20ae5a8ddda46b74382d60ec89b1b41320 (patch)
tree41f14d70ccf161842045646f1b0b8b21abae3d92
parentb71815a8d49f95657ce8253434187827e63a5ade (diff)
use unique_ptr for ScLookupCacheMap
Change-Id: Ib09a5331dfd57a99852555348c46730368d8d61d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100531 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sc/inc/interpretercontext.hxx12
-rw-r--r--sc/source/core/data/documen2.cxx12
-rw-r--r--sc/source/core/tool/interpretercontext.cxx17
3 files changed, 19 insertions, 22 deletions
diff --git a/sc/inc/interpretercontext.hxx b/sc/inc/interpretercontext.hxx
index 7eb1f1415642..2e0ff91632d6 100644
--- a/sc/inc/interpretercontext.hxx
+++ b/sc/inc/interpretercontext.hxx
@@ -57,21 +57,13 @@ struct ScInterpreterContext
size_t mnTokenCachePos;
std::vector<formula::FormulaToken*> maTokens;
std::vector<DelayedSetNumberFormat> maDelayedSetNumberFormat;
- ScLookupCacheMap* mScLookupCache; // cache for lookups like VLOOKUP and MATCH
+ std::unique_ptr<ScLookupCacheMap> mxScLookupCache; // cache for lookups like VLOOKUP and MATCH
// Allocation cache for "aConditions" array in ScInterpreter::IterateParameterIfs()
// This is populated/used only when formula-group threading is enabled.
std::vector<sal_uInt32> maConditions;
ScInterpreter* pInterpreter;
- ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter)
- : mpDoc(&rDoc)
- , mnTokenCachePos(0)
- , maTokens(TOKEN_CACHE_SIZE, nullptr)
- , mScLookupCache(nullptr)
- , pInterpreter(nullptr)
- , mpFormatter(pFormatter)
- {
- }
+ ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter);
ScInterpreterContext() = delete;
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index e4413853aa71..9d8ed27a82ce 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1151,14 +1151,14 @@ void ScDocument::DisposeFieldEditEngine(std::unique_ptr<ScFieldEditEngine>& rpEd
ScLookupCache & ScDocument::GetLookupCache( const ScRange & rRange, ScInterpreterContext* pContext )
{
ScLookupCache* pCache = nullptr;
- ScLookupCacheMap*& rpCacheMap = pContext->mScLookupCache;
- if (!rpCacheMap)
- rpCacheMap = new ScLookupCacheMap;
+ if (!pContext->mxScLookupCache)
+ pContext->mxScLookupCache.reset(new ScLookupCacheMap);
+ ScLookupCacheMap* pCacheMap = pContext->mxScLookupCache.get();
// insert with temporary value to avoid doing two lookups
- auto [findIt, bInserted] = rpCacheMap->aCacheMap.emplace(rRange, nullptr);
+ auto [findIt, bInserted] = pCacheMap->aCacheMap.emplace(rRange, nullptr);
if (bInserted)
{
- findIt->second = std::make_unique<ScLookupCache>(this, rRange, *rpCacheMap);
+ findIt->second = std::make_unique<ScLookupCache>(this, rRange, *pCacheMap);
pCache = findIt->second.get();
// The StartListeningArea() call is not thread-safe, as all threads
// would access the same SvtBroadcaster.
@@ -1193,7 +1193,7 @@ void ScDocument::RemoveLookupCache( ScLookupCache & rCache )
void ScDocument::ClearLookupCaches()
{
assert(!IsThreadedGroupCalcInProgress());
- DELETEZ(GetNonThreadedContext().mScLookupCache);
+ GetNonThreadedContext().mxScLookupCache.reset();
// Clear lookup cache in all interpreter-contexts in the (threaded/non-threaded) pools.
ScInterpreterContextPool::ClearLookupCaches();
}
diff --git a/sc/source/core/tool/interpretercontext.cxx b/sc/source/core/tool/interpretercontext.cxx
index 77d2feadce6a..ce02ea28d52c 100644
--- a/sc/source/core/tool/interpretercontext.cxx
+++ b/sc/source/core/tool/interpretercontext.cxx
@@ -28,10 +28,19 @@
ScInterpreterContextPool ScInterpreterContextPool::aThreadedInterpreterPool(true);
ScInterpreterContextPool ScInterpreterContextPool::aNonThreadedInterpreterPool(false);
+ScInterpreterContext::ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter)
+ : mpDoc(&rDoc)
+ , mnTokenCachePos(0)
+ , maTokens(TOKEN_CACHE_SIZE, nullptr)
+ , pInterpreter(nullptr)
+ , mpFormatter(pFormatter)
+{
+}
+
ScInterpreterContext::~ScInterpreterContext()
{
ResetTokens();
- delete mScLookupCache;
+ mxScLookupCache.reset();
}
void ScInterpreterContext::ResetTokens()
@@ -63,11 +72,7 @@ void ScInterpreterContext::Cleanup()
ResetTokens();
}
-void ScInterpreterContext::ClearLookupCache()
-{
- delete mScLookupCache;
- mScLookupCache = nullptr;
-}
+void ScInterpreterContext::ClearLookupCache() { mxScLookupCache.reset(); }
SvNumFormatType ScInterpreterContext::GetNumberFormatType(sal_uInt32 nFIndex) const
{