diff options
-rw-r--r-- | sc/inc/document.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 83 |
2 files changed, 19 insertions, 67 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 74c5b65d3c34..1bb1f65aab3c 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1290,9 +1290,6 @@ public: /** Creates a ScLookupCache cache for the range if it doesn't already exist. */ ScLookupCache & GetLookupCache( const ScRange & rRange ); - /** Only ScLookupCache ctor uses AddLookupCache(), do not - use elsewhere! */ - void AddLookupCache( ScLookupCache & rCache ); /** Only ScLookupCache dtor uses RemoveLookupCache(), do not use elsewhere! */ void RemoveLookupCache( ScLookupCache & rCache ); diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 4dde125e4dba..30c1e4015889 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -113,23 +113,10 @@ using namespace com::sun::star; // dtor plus helpers are convenient. struct ScLookupCacheMapImpl { - std::unordered_map< ScRange, ScLookupCache*, ScLookupCache::Hash > aCacheMap; - ~ScLookupCacheMapImpl() - { - freeCaches(); - } + std::unordered_map< ScRange, std::unique_ptr<ScLookupCache>, ScLookupCache::Hash > aCacheMap; void clear() { - freeCaches(); - // free mapping - std::unordered_map< ScRange, ScLookupCache*, ScLookupCache::Hash > aTmp; - aCacheMap.swap( aTmp); - } -private: - void freeCaches() - { - for (auto& aCacheItem : aCacheMap) - delete aCacheItem.second; + aCacheMap.clear(); } }; @@ -1190,57 +1177,25 @@ ScRecursionHelper* ScDocument::CreateRecursionHelperInstance() ScLookupCache & ScDocument::GetLookupCache( const ScRange & rRange ) { ScLookupCache* pCache = nullptr; - if (!IsThreadedGroupCalcInProgress()) + ScLookupCacheMapImpl*& rpCacheMapImpl ( + !IsThreadedGroupCalcInProgress() + ? maNonThreaded.pLookupCacheMapImpl + : maThreadSpecific.pLookupCacheMapImpl ); + + if (!rpCacheMapImpl) + rpCacheMapImpl = new ScLookupCacheMapImpl; + auto findIt(rpCacheMapImpl->aCacheMap.find(rRange)); + if (findIt == rpCacheMapImpl->aCacheMap.end()) { - if (!maNonThreaded.pLookupCacheMapImpl) - maNonThreaded.pLookupCacheMapImpl = new ScLookupCacheMapImpl; - auto it(maNonThreaded.pLookupCacheMapImpl->aCacheMap.find(rRange)); - if (it == maNonThreaded.pLookupCacheMapImpl->aCacheMap.end()) - { - pCache = new ScLookupCache(this, rRange); - AddLookupCache(*pCache); - } - else - pCache = (*it).second; + auto insertIt = rpCacheMapImpl->aCacheMap.emplace_hint(findIt, + rRange, o3tl::make_unique<ScLookupCache>(this, rRange) ); + pCache = insertIt->second.get(); + StartListeningArea(rRange, false, pCache); } else - { - if (!maThreadSpecific.pLookupCacheMapImpl) - maThreadSpecific.pLookupCacheMapImpl = new ScLookupCacheMapImpl; - auto it(maThreadSpecific.pLookupCacheMapImpl->aCacheMap.find(rRange)); - if (it == maThreadSpecific.pLookupCacheMapImpl->aCacheMap.end()) - { - pCache = new ScLookupCache(this, rRange); - AddLookupCache(*pCache); - } - else - pCache = (*it).second; - } - return *pCache; -} + pCache = (*findIt).second.get(); -void ScDocument::AddLookupCache( ScLookupCache & rCache ) -{ - if (!IsThreadedGroupCalcInProgress()) - { - if (!maNonThreaded.pLookupCacheMapImpl->aCacheMap.insert( ::std::pair< const ScRange, - ScLookupCache*>(rCache.getRange(), &rCache)).second) - { - OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map"); - } - else - StartListeningArea(rCache.getRange(), false, &rCache); - } - else - { - if (!maThreadSpecific.pLookupCacheMapImpl->aCacheMap.insert( ::std::pair< const ScRange, - ScLookupCache*>(rCache.getRange(), &rCache)).second) - { - OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map"); - } - else - StartListeningArea(rCache.getRange(), false, &rCache); - } + return *pCache; } void ScDocument::RemoveLookupCache( ScLookupCache & rCache ) @@ -1254,7 +1209,7 @@ void ScDocument::RemoveLookupCache( ScLookupCache & rCache ) } else { - ScLookupCache* pCache = (*it).second; + ScLookupCache* pCache = (*it).second.release(); maNonThreaded.pLookupCacheMapImpl->aCacheMap.erase(it); EndListeningArea(pCache->getRange(), false, &rCache); } @@ -1268,7 +1223,7 @@ void ScDocument::RemoveLookupCache( ScLookupCache & rCache ) } else { - ScLookupCache* pCache = (*it).second; + ScLookupCache* pCache = (*it).second.release(); maThreadSpecific.pLookupCacheMapImpl->aCacheMap.erase(it); EndListeningArea(pCache->getRange(), false, &rCache); } |