include/svtools/imap.hxx | 1 + sfx2/source/bastyp/sfxhtml.cxx | 24 ++++++++++++------------ svtools/source/misc/imap.cxx | 4 ++++ svtools/source/uno/unoimap.cxx | 17 ++++++++--------- vcl/inc/unx/glyphcache.hxx | 2 +- vcl/unx/generic/glyphs/glyphcache.cxx | 14 +++++++------- 6 files changed, 33 insertions(+), 29 deletions(-)
New commits: commit 0b6f2f3ff47b6f1455d213bee4b257542e527976 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Aug 13 14:50:13 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Aug 15 08:40:50 2018 +0200 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: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/vcl/inc/unx/glyphcache.hxx b/vcl/inc/unx/glyphcache.hxx index 50d1f071d44f..03571c3ee4e4 100644 --- a/vcl/inc/unx/glyphcache.hxx +++ b/vcl/inc/unx/glyphcache.hxx @@ -85,7 +85,7 @@ private: // the FontList key's mpFontData member is reinterpreted as integer font id struct IFSD_Equal{ bool operator()( const FontSelectPattern&, 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; sal_uLong mnMaxSize; // max overall cache size in bytes diff --git a/vcl/unx/generic/glyphs/glyphcache.cxx b/vcl/unx/generic/glyphs/glyphcache.cxx index e43b6db2e238..908f570a1c9d 100644 --- a/vcl/unx/generic/glyphs/glyphcache.cxx +++ b/vcl/unx/generic/glyphs/glyphcache.cxx @@ -50,12 +50,12 @@ GlyphCache::~GlyphCache() 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 pFreetypeFont->GarbageCollect( mnLruIndex+0x10000000 ); - delete pFreetypeFont; + font.second.reset(); } maFontList.clear(); @@ -66,7 +66,7 @@ void GlyphCache::ClearFontOptions() { for (auto const& font : maFontList) { - FreetypeFont* pFreetypeFont = font.second; + FreetypeFont* pFreetypeFont = font.second.get(); // free demand-loaded FontConfig related data pFreetypeFont->ClearFontOptions(); } @@ -183,7 +183,7 @@ FreetypeFont* GlyphCache::CacheFont( const FontSelectPattern& rFontSelData ) FontList::iterator it = maFontList.find(rFontSelData); if( it != maFontList.end() ) { - FreetypeFont* pFound = it->second; + FreetypeFont* pFound = it->second.get(); assert(pFound); pFound->AddRef(); return pFound; @@ -196,7 +196,7 @@ FreetypeFont* GlyphCache::CacheFont( const FontSelectPattern& rFontSelData ) if( pNew ) { - maFontList[ rFontSelData ] = pNew; + maFontList[ rFontSelData ].reset(pNew); mnBytesUsed += pNew->GetByteCount(); // enable garbage collection for new font @@ -234,7 +234,7 @@ void GlyphCache::GarbageCollect() { FontList::iterator it = maFontList.begin(); if( it != maFontList.end() ) - mpCurrentGCFont = it->second; + mpCurrentGCFont = it->second.get(); } // unless there is no other font to collect commit 3deaeb9380d43d35cba82e1427492ca6ad0ea01f Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Aug 13 14:49:37 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Aug 15 08:40:38 2018 +0200 pass IMapObject around by std::unique_ptr and avoid some unnecessary copying Change-Id: Ieb9b1fe169a7d56197bf1e054e9af5dca7804301 Reviewed-on: https://gerrit.libreoffice.org/59019 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/svtools/imap.hxx b/include/svtools/imap.hxx index af094cbab817..e0129bffce07 100644 --- a/include/svtools/imap.hxx +++ b/include/svtools/imap.hxx @@ -77,6 +77,7 @@ public: // a new IMap object is inserted at the end of the Map void InsertIMapObject( const IMapObject& rIMapObject ); + void InsertIMapObject( std::unique_ptr<IMapObject> rIMapObject ); // access to the single ImapObjects; the objects may // not be destroyed from outside diff --git a/sfx2/source/bastyp/sfxhtml.cxx b/sfx2/source/bastyp/sfxhtml.cxx index e64dd7ed714e..40095fdbb7fb 100644 --- a/sfx2/source/bastyp/sfxhtml.cxx +++ b/sfx2/source/bastyp/sfxhtml.cxx @@ -182,22 +182,22 @@ IMAPOBJ_SETEVENT: { tools::Rectangle aRect( aCoords[0], aCoords[1], aCoords[2], aCoords[3] ); - IMapRectangleObject aMapRObj( aRect, aHRef, aAlt, OUString(), aTarget, aName, - !bNoHRef ); + std::unique_ptr<IMapRectangleObject> pMapRObj( new IMapRectangleObject(aRect, aHRef, aAlt, OUString(), aTarget, aName, + !bNoHRef )); if( !aMacroTbl.empty() ) - aMapRObj.SetMacroTable( aMacroTbl ); - pImageMap->InsertIMapObject( aMapRObj ); + pMapRObj->SetMacroTable( aMacroTbl ); + pImageMap->InsertIMapObject( std::move(pMapRObj) ); } break; case IMAP_OBJ_CIRCLE: if( aCoords.size() >=3 ) { Point aPoint( aCoords[0], aCoords[1] ); - IMapCircleObject aMapCObj( aPoint, aCoords[2],aHRef, aAlt, OUString(), - aTarget, aName, !bNoHRef ); + std::unique_ptr<IMapCircleObject> pMapCObj(new IMapCircleObject(aPoint, aCoords[2],aHRef, aAlt, OUString(), + aTarget, aName, !bNoHRef )); if( !aMacroTbl.empty() ) - aMapCObj.SetMacroTable( aMacroTbl ); - pImageMap->InsertIMapObject( aMapCObj ); + pMapCObj->SetMacroTable( aMacroTbl ); + pImageMap->InsertIMapObject( std::move(pMapCObj) ); } break; case IMAP_OBJ_POLYGON: @@ -207,11 +207,11 @@ IMAPOBJ_SETEVENT: tools::Polygon aPoly( nCount ); for( sal_uInt16 i=0; i<nCount; i++ ) aPoly[i] = Point( aCoords[2*i], aCoords[2*i+1] ); - IMapPolygonObject aMapPObj( aPoly, aHRef, aAlt, OUString(), aTarget, aName, - !bNoHRef ); + std::unique_ptr<IMapPolygonObject> pMapPObj(new IMapPolygonObject( aPoly, aHRef, aAlt, OUString(), aTarget, aName, + !bNoHRef )); if( !aMacroTbl.empty() ) - aMapPObj.SetMacroTable( aMacroTbl ); - pImageMap->InsertIMapObject( aMapPObj ); + pMapPObj->SetMacroTable( aMacroTbl ); + pImageMap->InsertIMapObject( std::move(pMapPObj) ); } break; default: diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx index 5118f52db82d..4e23ef612173 100644 --- a/svtools/source/misc/imap.cxx +++ b/svtools/source/misc/imap.cxx @@ -758,6 +758,10 @@ void ImageMap::InsertIMapObject( const IMapObject& rIMapObject ) } } +void ImageMap::InsertIMapObject( std::unique_ptr<IMapObject> pNewObject ) +{ + maList.emplace_back( std::move(pNewObject) ); +} /****************************************************************************** |* diff --git a/svtools/source/uno/unoimap.cxx b/svtools/source/uno/unoimap.cxx index 4c337df681d3..2999b5aff1a3 100644 --- a/svtools/source/uno/unoimap.cxx +++ b/svtools/source/uno/unoimap.cxx @@ -78,7 +78,7 @@ public: UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject ) - IMapObject* createIMapObject() const; + std::unique_ptr<IMapObject> createIMapObject() const; rtl::Reference<SvMacroTableEventDescriptor> mxEvents; @@ -246,7 +246,7 @@ SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const Sv mxEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems ); } -IMapObject* SvUnoImageMapObject::createIMapObject() const +std::unique_ptr<IMapObject> SvUnoImageMapObject::createIMapObject() const { const OUString aURL( maURL ); const OUString aAltText( maAltText ); @@ -254,21 +254,21 @@ IMapObject* SvUnoImageMapObject::createIMapObject() const const OUString aTarget( maTarget ); const OUString aName( maName ); - IMapObject* pNewIMapObject; + std::unique_ptr<IMapObject> pNewIMapObject; switch( mnType ) { case IMAP_OBJ_RECTANGLE: { const tools::Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 ); - pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false ); + pNewIMapObject.reset(new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); } break; case IMAP_OBJ_CIRCLE: { const Point aCenter( maCenter.X, maCenter.Y ); - pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false ); + pNewIMapObject.reset(new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); } break; @@ -285,7 +285,7 @@ IMapObject* SvUnoImageMapObject::createIMapObject() const } aPoly.Optimize( PolyOptimizeFlags::CLOSE ); - pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false ); + pNewIMapObject.reset(new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); } break; } @@ -675,9 +675,8 @@ void SvUnoImageMap::fillImageMap( ImageMap& rMap ) const for (auto const& elem : maObjectList) { - IMapObject* pNewMapObject = elem->createIMapObject(); - rMap.InsertIMapObject( *pNewMapObject ); - delete pNewMapObject; + std::unique_ptr<IMapObject> pNewMapObject = elem->createIMapObject(); + rMap.InsertIMapObject( std::move(pNewMapObject) ); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits