diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-06-03 14:35:27 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-06-03 21:59:21 +0200 |
commit | 4aa6ae8ba911bd3420d3b74c085aa69d87339f4d (patch) | |
tree | 348c48a358be1567401d979e927ffbfb8594da17 /svl | |
parent | a80c8892d32185224474c862e032c690fc8bffe6 (diff) |
fix ubsan in SharedStringPool
with a slightly dodgy fix.
regression from
commit 3581f1d71ae0d431ba28c0f3b7b263ff6212ce7b
optimize SharedStringPool::purge() and fix tests
It's not ideal - we no longer have a way of purging uppercase keys that
are longer in use.
But that doesn't cost much memory, because we are sharing those strings.
We could potentially identify them with extra book-keeping in either
intern() or purge(), but since this class is performance-sensitive, best
just to sacrifice some space in the map.
Change-Id: I85a469448f5b36b1b6889da60280edd56bbcb083
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95432
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/qa/unit/svl.cxx | 4 | ||||
-rw-r--r-- | svl/source/misc/sharedstringpool.cxx | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 6b44a96729d1..2c266e4d9d31 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -392,10 +392,10 @@ void Test::testSharedStringPoolPurge() CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aPool.getCount()); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPool.getCountIgnoreCase()); - // Ditto... + // Nothing changes, because the upper-string is still in the map pStr3.reset(); aPool.purge(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aPool.getCount()); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aPool.getCountIgnoreCase()); // Again. diff --git a/svl/source/misc/sharedstringpool.cxx b/svl/source/misc/sharedstringpool.cxx index 25898084f327..d2d890004fbd 100644 --- a/svl/source/misc/sharedstringpool.cxx +++ b/svl/source/misc/sharedstringpool.cxx @@ -60,7 +60,12 @@ SharedString SharedStringPool::intern( const OUString& rStr ) // need to use the same underlying rtl_uString object so the // upper->upper detection in purge() works auto pData = insertResult.first->pData; - mpImpl->maStrMap.insert_or_assign(mapIt, pData, pData); + // This is dodgy, but necessary. I don't want to do a delete/insert because + // this class is very performance sensitive. This does not violate the internals + // the map because the new key points to something with the same hash and equality + // as the old key. + const_cast<OUString&>(mapIt->first) = *insertResult.first; + mapIt->second = pData; } else { |