vcl/inc/fontinstance.hxx         |   19 ++++++++++++++++++-
 vcl/source/font/fontinstance.cxx |   38 +++++++-------------------------------
 2 files changed, 25 insertions(+), 32 deletions(-)

New commits:
commit d73551e4023f2c9de5adaaba3d2dc0e940de41e4
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Mar 8 10:29:13 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Mar 8 15:40:41 2022 +0100

    no need to allocate fallback list separately
    
    an empty map is just a couple of words of storage anyway
    
    Change-Id: Ic14eb370cee5522f435c6709529c8480d2af9e13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131170
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index d23c6a58548d..5822bd1a08b5 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -22,6 +22,7 @@
 #include <sal/config.h>
 
 #include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <o3tl/hash_combine.hxx>
 #include <rtl/ref.hxx>
 #include <salhelper/simplereferenceobject.hxx>
 #include <tools/gen.hxx>
@@ -41,6 +42,22 @@
 class ConvertChar;
 class ImplFontCache;
 
+// extend std namespace to add custom hash needed for LogicalFontInstance
+
+namespace std
+{
+    template <> struct hash< pair< sal_UCS4, FontWeight > >
+    {
+        size_t operator()(const pair< sal_UCS4, FontWeight >& rData) const
+        {
+            std::size_t seed = 0;
+            o3tl::hash_combine(seed, rData.first);
+            o3tl::hash_combine(seed, rData.second);
+            return seed;
+        }
+    };
+}
+
 // TODO: allow sharing of metrics for related fonts
 
 class VCL_PLUGIN_PUBLIC LogicalFontInstance : public 
salhelper::SimpleReferenceObject
@@ -105,7 +122,7 @@ private:
     // TODO: a fallback map can be shared with many other ImplFontEntries
     // TODO: at least the ones which just differ in orientation, stretching or 
height
     typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, MapEntry > 
UnicodeFallbackList;
-    std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
+    UnicodeFallbackList maUnicodeFallbackList;
     mutable ImplFontCache * mpFontCache;
     const vcl::font::FontSelectPattern m_aFontSelData;
     hb_font_t* m_pHbFont;
diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx
index 54464b101d72..5dbd1748a3c3 100644
--- a/vcl/source/font/fontinstance.cxx
+++ b/vcl/source/font/fontinstance.cxx
@@ -26,25 +26,6 @@
 #include <fontinstance.hxx>
 #include <impfontcache.hxx>
 
-#include <o3tl/hash_combine.hxx>
-
-// extend std namespace to add custom hash needed for LogicalFontInstance
-
-namespace std
-{
-    template <> struct hash< pair< sal_UCS4, FontWeight > >
-    {
-        size_t operator()(const pair< sal_UCS4, FontWeight >& rData) const
-        {
-            std::size_t seed = 0;
-            o3tl::hash_combine(seed, rData.first);
-            o3tl::hash_combine(seed, rData.second);
-            return seed;
-        }
-    };
-}
-
-
 LogicalFontInstance::LogicalFontInstance(const vcl::font::PhysicalFontFace& 
rFontFace, const vcl::font::FontSelectPattern& rFontSelData )
     : mxFontMetric( new ImplFontMetricData( rFontSelData ))
     , mpConversion( nullptr )
@@ -62,7 +43,7 @@ LogicalFontInstance::LogicalFontInstance(const 
vcl::font::PhysicalFontFace& rFon
 
 LogicalFontInstance::~LogicalFontInstance()
 {
-    mpUnicodeFallbackList.reset();
+    maUnicodeFallbackList.clear();
     mpFontCache = nullptr;
     mxFontMetric = nullptr;
 
@@ -121,9 +102,7 @@ void LogicalFontInstance::GetScale(double* nXScale, double* 
nYScale)
 void LogicalFontInstance::AddFallbackForUnicode(sal_UCS4 cChar, FontWeight 
eWeight, const OUString& rFontName,
                                                 bool bEmbolden, const 
ItalicMatrix& rMatrix)
 {
-    if( !mpUnicodeFallbackList )
-        mpUnicodeFallbackList.reset(new UnicodeFallbackList);
-    MapEntry& rEntry = (*mpUnicodeFallbackList)[ std::pair< sal_UCS4, 
FontWeight >(cChar,eWeight) ];
+    MapEntry& rEntry = maUnicodeFallbackList[ std::pair< sal_UCS4, FontWeight 
>(cChar,eWeight) ];
     rEntry.sFontName = rFontName;
     rEntry.bEmbolden = bEmbolden;
     rEntry.aItalicMatrix = rMatrix;
@@ -132,11 +111,8 @@ void LogicalFontInstance::AddFallbackForUnicode(sal_UCS4 
cChar, FontWeight eWeig
 bool LogicalFontInstance::GetFallbackForUnicode(sal_UCS4 cChar, FontWeight 
eWeight,
                                                 OUString* pFontName, bool* 
pEmbolden, ItalicMatrix* pMatrix) const
 {
-    if( !mpUnicodeFallbackList )
-        return false;
-
-    UnicodeFallbackList::const_iterator it = mpUnicodeFallbackList->find( 
std::pair< sal_UCS4, FontWeight >(cChar,eWeight) );
-    if( it == mpUnicodeFallbackList->end() )
+    UnicodeFallbackList::const_iterator it = maUnicodeFallbackList.find( 
std::pair< sal_UCS4, FontWeight >(cChar,eWeight) );
+    if( it == maUnicodeFallbackList.end() )
         return false;
 
     const MapEntry& rEntry = (*it).second;
@@ -148,12 +124,12 @@ bool LogicalFontInstance::GetFallbackForUnicode(sal_UCS4 
cChar, FontWeight eWeig
 
 void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight 
eWeight, std::u16string_view rFontName )
 {
-    UnicodeFallbackList::iterator it = mpUnicodeFallbackList->find( std::pair< 
sal_UCS4,FontWeight >(cChar,eWeight) );
-    if( it == mpUnicodeFallbackList->end() )
+    UnicodeFallbackList::iterator it = maUnicodeFallbackList.find( std::pair< 
sal_UCS4,FontWeight >(cChar,eWeight) );
+    if( it == maUnicodeFallbackList.end() )
         return;
     const MapEntry& rEntry = (*it).second;
     if (rEntry.sFontName == rFontName)
-        mpUnicodeFallbackList->erase( it );
+        maUnicodeFallbackList.erase( it );
 }
 
 bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, tools::Rectangle 
&rRect, bool bVertical) const

Reply via email to