[Libreoffice-commits] core.git: sc/inc sc/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 11 19:54:56 UTC 2020
sc/inc/interpretercontext.hxx | 12 ++----------
sc/source/core/data/documen2.cxx | 12 ++++++------
sc/source/core/tool/interpretercontext.cxx | 17 +++++++++++------
3 files changed, 19 insertions(+), 22 deletions(-)
New commits:
commit 4cb85b20ae5a8ddda46b74382d60ec89b1b41320
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Aug 11 16:17:50 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Aug 11 21:54:08 2020 +0200
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 at collabora.co.uk>
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
{
More information about the Libreoffice-commits
mailing list