diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-05 17:08:49 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-06 16:23:44 +0200 |
commit | 16a338e173083954a9932a3a4005f172309c784e (patch) | |
tree | c401b0f8857e61147d5a0b2d7dc239fed9e047d5 /vcl/source/font | |
parent | 01a782d2ceb741d20721b44d26d862d80b47d226 (diff) |
Convert ImplFontCache to use o3tl::lru_map
We still do our own cleanup of the LRU map, as we can't drop
any fonts in use.
Change-Id: I8ec5c6ce8f80893635621357e9085950e7010f5b
Reviewed-on: https://gerrit.libreoffice.org/61455
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/source/font')
-rw-r--r-- | vcl/source/font/fontcache.cxx | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx index 0db997fe510f..2b2e062ecea0 100644 --- a/vcl/source/font/fontcache.cxx +++ b/vcl/source/font/fontcache.cxx @@ -85,13 +85,14 @@ bool ImplFontCache::IFSD_Equal::operator()(const FontSelectPattern& rA, const Fo ImplFontCache::ImplFontCache() : mpLastHitCacheEntry( nullptr ) + , maFontInstanceList(0) // The cache limit is set by the rough number of characters needed to read your average Asian newspaper. , m_aBoundRectCache(3000) {} ImplFontCache::~ImplFontCache() { - for (auto & rLFI : maFontInstanceList) + for (const auto & rLFI : maFontInstanceList) rLFI.second->mpFontCache = nullptr; } @@ -115,7 +116,7 @@ rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFont pFontInstance = mpLastHitCacheEntry; else { - FontInstanceList::iterator it = maFontInstanceList.find( aFontSelData ); + FontInstanceList::const_iterator it = maFontInstanceList.find( aFontSelData ); if( it != maFontInstanceList.end() ) pFontInstance = (*it).second; } @@ -130,7 +131,7 @@ rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFont aFontSelData.maSearchName = pFontFamily->GetSearchName(); // check if an indirectly matching logical font instance is already cached - FontInstanceList::iterator it = maFontInstanceList.find( aFontSelData ); + FontInstanceList::const_iterator it = maFontInstanceList.find( aFontSelData ); if( it != maFontInstanceList.end() ) pFontInstance = (*it).second; } @@ -168,25 +169,24 @@ rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( PhysicalFont if (maFontInstanceList.size() >= FONTCACHE_MAX) { - // remove entries from font instance cache that are only referenced by the cache - FontInstanceList::iterator it_next = maFontInstanceList.begin(); - while( it_next != maFontInstanceList.end() ) + struct limit_exception : public std::exception {}; + try { - LogicalFontInstance* pFontEntry = (*it_next).second.get(); - if( pFontEntry->m_nCount > 1 ) - { - ++it_next; - continue; - } - m_aBoundRectCache.remove_if([&pFontEntry] (GlpyhBoundRectCachePair const& rPair) - { return rPair.first.m_pFont == pFontEntry; } ); - - maFontInstanceList.erase(it_next); - if (mpLastHitCacheEntry == pFontEntry) - mpLastHitCacheEntry = nullptr; - // just remove one entry, which will bring us back under FONTCACHE_MAX size again - break; + maFontInstanceList.remove_if([this] (FontInstanceListPair const& rFontPair) + { + if (maFontInstanceList.size() < FONTCACHE_MAX) + throw limit_exception(); + LogicalFontInstance* pFontEntry = rFontPair.second.get(); + if (pFontEntry->m_nCount > 1) + return false; + m_aBoundRectCache.remove_if([&pFontEntry] (GlpyhBoundRectCachePair const& rGlyphPair) + { return rGlyphPair.first.m_pFont == pFontEntry; }); + if (mpLastHitCacheEntry == pFontEntry) + mpLastHitCacheEntry = nullptr; + return true; + }); } + catch (limit_exception) {} } assert(pFontInstance); |