From bc11ba676dd304e3deb481995e09c0902675503a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 16 May 2019 16:56:20 +0200 Subject: 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 --- svl/source/misc/sharedstringpool.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'svl') 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); } -- cgit