Kaydet (Commit) bc11ba67 authored tarafından Noel Grandin's avatar Noel Grandin

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

Change-Id: I40b9e2b65a831e44c4b88d51d835242a47d8a86d
Reviewed-on: https://gerrit.libreoffice.org/72516
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 35a9cbc4
......@@ -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;
auto insertResult = mpImpl->maStrPoolUpper.insert(aUpper);
mapIt->second = insertResult.first->pData;
return SharedString(mapIt->first.pData, mapIt->second);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment