remove the o3tl::lru_map "unlimited" hack

It didn't quite make sense before that maxsize == 0 meant no cleanup,
and now with items optionally being count as having size more than 1
it makes even less sense to limit the size to max_size() of the
containers. This comes from 16a338e173,
so instead make that special caller pass a large size, which in
practice is the same.

Change-Id: Id875862126200ba889211f6e4079ae5921f27650
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133690
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák 2022-05-02 10:52:50 +02:00
parent 1661a3ee77
commit 0cc8da4c09
3 changed files with 5 additions and 24 deletions

View file

@ -166,10 +166,10 @@ public:
typedef list_iterator_t iterator;
typedef list_const_iterator_t const_iterator;
// a size of 0 effectively disables the LRU cleanup code
lru_map(size_t nMaxSize)
: mMaxSize(nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), mLruList.max_size()))
: mMaxSize(nMaxSize)
{
assert(mMaxSize > 0);
}
~lru_map()
{
@ -182,7 +182,8 @@ public:
void setMaxSize(size_t nMaxSize)
{
mMaxSize = nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), mLruList.max_size());
mMaxSize = nMaxSize;
assert(mMaxSize > 0);
checkLRUMaxSize();
}

View file

@ -27,7 +27,6 @@ public:
void testLruRemoval();
void testCustomHash();
void testRemoveIf();
void testNoAutoCleanup();
void testChangeMaxSize();
void testCustomItemSize();
@ -38,7 +37,6 @@ public:
CPPUNIT_TEST(testLruRemoval);
CPPUNIT_TEST(testCustomHash);
CPPUNIT_TEST(testRemoveIf);
CPPUNIT_TEST(testNoAutoCleanup);
CPPUNIT_TEST(testChangeMaxSize);
CPPUNIT_TEST(testCustomItemSize);
CPPUNIT_TEST_SUITE_END();
@ -295,24 +293,6 @@ void lru_map_test::testRemoveIf()
CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
}
void lru_map_test::testNoAutoCleanup()
{
o3tl::lru_map<int, int> lru(0);
CPPUNIT_ASSERT_EQUAL(size_t(0), lru.size());
lru.insert({ 0, 0 });
lru.insert({ 1, 1 });
CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
lru.insert({ 0, 0 });
CPPUNIT_ASSERT_EQUAL(size_t(2), lru.size());
int i = 0;
for (auto& rPair : lru)
{
CPPUNIT_ASSERT_EQUAL(i, rPair.first);
++i;
}
}
void lru_map_test::testChangeMaxSize()
{
o3tl::lru_map<int, int> lru(3);

View file

@ -88,7 +88,7 @@ bool ImplFontCache::IFSD_Equal::operator()(const vcl::font::FontSelectPattern& r
ImplFontCache::ImplFontCache()
: mpLastHitCacheEntry( nullptr )
, maFontInstanceList(0)
, maFontInstanceList(std::numeric_limits<size_t>::max()) // "unlimited", i.e. no cleanup
// The cache limit is set by the rough number of characters needed to read your average Asian newspaper.
, m_aBoundRectCache(3000)
{}