[Libreoffice-commits] core.git: svl/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sat May 18 12:08:45 UTC 2019
svl/source/misc/sharedstringpool.cxx | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
New commits:
commit bc11ba676dd304e3deb481995e09c0902675503a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu May 16 16:56:20 2019 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat May 18 14:07:36 2019 +0200
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 at collabora.co.uk>
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);
}
More information about the Libreoffice-commits
mailing list