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

loplugin:useuniqueptr in GlyphCache

although I rather suspect these FreetypeFont objects would be better
held by rtl::Reference

Change-Id: I1a7d6ca47d1f78686637368a4bec57b1fcfaa6e9
Reviewed-on: https://gerrit.libreoffice.org/59020
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 3deaeb93
...@@ -85,7 +85,7 @@ private: ...@@ -85,7 +85,7 @@ private:
// the FontList key's mpFontData member is reinterpreted as integer font id // the FontList key's mpFontData member is reinterpreted as integer font id
struct IFSD_Equal{ bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; }; struct IFSD_Equal{ bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; };
struct IFSD_Hash{ size_t operator()( const FontSelectPattern& ) const; }; struct IFSD_Hash{ size_t operator()( const FontSelectPattern& ) const; };
typedef std::unordered_map<FontSelectPattern,FreetypeFont*,IFSD_Hash,IFSD_Equal > FontList; typedef std::unordered_map<FontSelectPattern,std::unique_ptr<FreetypeFont>,IFSD_Hash,IFSD_Equal > FontList;
FontList maFontList; FontList maFontList;
sal_uLong mnMaxSize; // max overall cache size in bytes sal_uLong mnMaxSize; // max overall cache size in bytes
......
...@@ -50,12 +50,12 @@ GlyphCache::~GlyphCache() ...@@ -50,12 +50,12 @@ GlyphCache::~GlyphCache()
void GlyphCache::InvalidateAllGlyphs() void GlyphCache::InvalidateAllGlyphs()
{ {
for (auto const& font : maFontList) for (auto& font : maFontList)
{ {
FreetypeFont* pFreetypeFont = font.second; FreetypeFont* pFreetypeFont = font.second.get();
// free all pFreetypeFont related data // free all pFreetypeFont related data
pFreetypeFont->GarbageCollect( mnLruIndex+0x10000000 ); pFreetypeFont->GarbageCollect( mnLruIndex+0x10000000 );
delete pFreetypeFont; font.second.reset();
} }
maFontList.clear(); maFontList.clear();
...@@ -66,7 +66,7 @@ void GlyphCache::ClearFontOptions() ...@@ -66,7 +66,7 @@ void GlyphCache::ClearFontOptions()
{ {
for (auto const& font : maFontList) for (auto const& font : maFontList)
{ {
FreetypeFont* pFreetypeFont = font.second; FreetypeFont* pFreetypeFont = font.second.get();
// free demand-loaded FontConfig related data // free demand-loaded FontConfig related data
pFreetypeFont->ClearFontOptions(); pFreetypeFont->ClearFontOptions();
} }
...@@ -183,7 +183,7 @@ FreetypeFont* GlyphCache::CacheFont( const FontSelectPattern& rFontSelData ) ...@@ -183,7 +183,7 @@ FreetypeFont* GlyphCache::CacheFont( const FontSelectPattern& rFontSelData )
FontList::iterator it = maFontList.find(rFontSelData); FontList::iterator it = maFontList.find(rFontSelData);
if( it != maFontList.end() ) if( it != maFontList.end() )
{ {
FreetypeFont* pFound = it->second; FreetypeFont* pFound = it->second.get();
assert(pFound); assert(pFound);
pFound->AddRef(); pFound->AddRef();
return pFound; return pFound;
...@@ -196,7 +196,7 @@ FreetypeFont* GlyphCache::CacheFont( const FontSelectPattern& rFontSelData ) ...@@ -196,7 +196,7 @@ FreetypeFont* GlyphCache::CacheFont( const FontSelectPattern& rFontSelData )
if( pNew ) if( pNew )
{ {
maFontList[ rFontSelData ] = pNew; maFontList[ rFontSelData ].reset(pNew);
mnBytesUsed += pNew->GetByteCount(); mnBytesUsed += pNew->GetByteCount();
// enable garbage collection for new font // enable garbage collection for new font
...@@ -234,7 +234,7 @@ void GlyphCache::GarbageCollect() ...@@ -234,7 +234,7 @@ void GlyphCache::GarbageCollect()
{ {
FontList::iterator it = maFontList.begin(); FontList::iterator it = maFontList.begin();
if( it != maFontList.end() ) if( it != maFontList.end() )
mpCurrentGCFont = it->second; mpCurrentGCFont = it->second.get();
} }
// unless there is no other font to collect // unless there is no other font to collect
......
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