summaryrefslogtreecommitdiffstats
path: root/svl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-05-16 16:56:20 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-05-18 14:07:36 +0200
commitbc11ba676dd304e3deb481995e09c0902675503a (patch)
treec1d2c75d1d3d865a8e064e6e81abbea58612b28c /svl
parentUpdate git submodules (diff)
downloadcore-bc11ba676dd304e3deb481995e09c0902675503a.tar.gz
core-bc11ba676dd304e3deb481995e09c0902675503a.zip
avoid double-lookup in SharedStringPool::intern
An emplace_hint with the iterator pointing at end() doesn't really help, so rather attempt an insert with a temporary value. Also check if the upper-case string we got back is the same as the input string, in which case, we can save memory by mapping the input string to itself. Change-Id: I40b9e2b65a831e44c4b88d51d835242a47d8a86d Reviewed-on: https://gerrit.libreoffice.org/72516 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/misc/sharedstringpool.cxx16
1 files changed, 12 insertions, 4 deletions
diff --git a/svl/source/misc/sharedstringpool.cxx b/svl/source/misc/sharedstringpool.cxx
index ad72b5a1addb..5c26c912bc42 100644
--- a/svl/source/misc/sharedstringpool.cxx
+++ b/svl/source/misc/sharedstringpool.cxx
@@ -49,13 +49,21 @@ SharedString SharedStringPool::intern( const OUString& rStr )
{
osl::MutexGuard aGuard(&mpImpl->maMutex);
- auto mapIt = mpImpl->maStrMap.find(rStr);
- if (mapIt == mpImpl->maStrMap.end())
+ auto [mapIt,bInserted] = mpImpl->maStrMap.emplace(rStr, rStr.pData);
+ if (bInserted)
{
// This is a new string insertion. Establish mapping to upper-case variant.
OUString aUpper = mpImpl->mrCharClass.uppercase(rStr);
- auto insertResult = mpImpl->maStrPoolUpper.insert(aUpper);
- mapIt = mpImpl->maStrMap.emplace_hint(mapIt, rStr, insertResult.first->pData);
+ if (aUpper == rStr)
+ {
+ auto insertResult = mpImpl->maStrPoolUpper.insert(rStr);
+ mapIt->second = insertResult.first->pData;
+ }
+ else
+ {
+ auto insertResult = mpImpl->maStrPoolUpper.insert(aUpper);
+ mapIt->second = insertResult.first->pData;
+ }
}
return SharedString(mapIt->first.pData, mapIt->second);
}