svl/qa/unit/svl.cxx | 4 ++-- svl/source/misc/sharedstringpool.cxx | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-)
New commits: commit c344de1b9985b6ca10b354e24151d0bdf92dc20e Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Jun 3 14:35:27 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Jun 4 18:49:40 2020 +0200 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.gran...@collabora.co.uk> (cherry picked from commit 4aa6ae8ba911bd3420d3b74c085aa69d87339f4d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95426 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 { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits