[Libreoffice-commits] core.git: sc/inc sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Aug 22 13:31:27 UTC 2018
sc/inc/document.hxx | 3 -
sc/source/core/data/documen2.cxx | 83 ++++++++-------------------------------
2 files changed, 19 insertions(+), 67 deletions(-)
New commits:
commit fe8b2398b2850f210c6d4fbcb5edd614194787f3
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Aug 22 10:50:52 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 22 15:31:03 2018 +0200
loplugin:useuniqueptr in ScLookupCacheMapImpl
and simplify
Change-Id: Ic5ec97680349a1ea837891b2300dff05cd00026f
Reviewed-on: https://gerrit.libreoffice.org/59431
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
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);
}
More information about the Libreoffice-commits
mailing list