[Libreoffice-commits] core.git: compilerplugins/clang idlc/source sal/rtl sfx2/source vcl/skia

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 23 09:23:31 UTC 2021


 compilerplugins/clang/badstatics.cxx |    2 +
 idlc/source/idlcproduce.cxx          |   28 ++++++++++-------------
 sal/rtl/locale.cxx                   |   16 ++++---------
 sfx2/source/view/frame.cxx           |   20 ++++++-----------
 vcl/skia/SkiaHelper.cxx              |   41 +++++++++++++----------------------
 5 files changed, 43 insertions(+), 64 deletions(-)

New commits:
commit 4e512171c21a193027c35d19a5273507a2725596
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 22 11:11:27 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jul 23 11:22:59 2021 +0200

    no need to allocate these static vars on demand
    
    the constructor can be laid out at compile/link time
    
    Change-Id: I377a537e15199ae81394d76ac662576280a25c25
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119362
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx
index 0856d8faac39..1c6a2f2998f3 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -222,6 +222,8 @@ public:
                    // sfx2/source/doc/docfile.cxx, warning about map's key
                 || name == "g_existingReadOnlyDocs"
                    // sfx2/source/doc/docfile.cxx, warning about map's key
+                || name == "gaFramesArr_Impl"
+                   // sfx2/source/view/frame.cxx, vector of pointer, so not a problem, nothing is going to happen on shutdown
                ) // these variables appear unproblematic
             {
                 return true;
diff --git a/idlc/source/idlcproduce.cxx b/idlc/source/idlcproduce.cxx
index 92e7887236d2..e5ea206f0ff8 100644
--- a/idlc/source/idlcproduce.cxx
+++ b/idlc/source/idlcproduce.cxx
@@ -39,7 +39,7 @@
 
 using namespace ::osl;
 
-static std::list< OString >* pCreatedDirectories = nullptr;
+static std::list< OString > gaCreatedDirectories;
 
 static bool checkOutputPath(const OString& completeName)
 {
@@ -79,11 +79,10 @@ static bool checkOutputPath(const OString& completeName)
                             idlc()->getOptions()->getProgramName().getStr(), buffer.getStr());
                     return false;
                 }
-            } else
+            }
+            else
             {
-                if ( !pCreatedDirectories )
-                    pCreatedDirectories = new std::list< OString >;
-                pCreatedDirectories->push_front(buffer.getStr());
+                gaCreatedDirectories.push_front(buffer.getStr());
             }
         }
         buffer.append(SEPARATOR);
@@ -93,23 +92,20 @@ static bool checkOutputPath(const OString& completeName)
 
 static bool cleanPath()
 {
-    if ( pCreatedDirectories )
+    for (auto const& createdDirectory : gaCreatedDirectories)
     {
-        for (auto const& createdDirectory : *pCreatedDirectories)
-        {
 //#ifdef SAL_UNX
-//          if (rmdir((char*)createdDirectory.getStr(), 0777) == -1)
+//      if (rmdir((char*)createdDirectory.getStr(), 0777) == -1)
 //#else
-            if (rmdir(createdDirectory.getStr()) == -1)
+        if (rmdir(createdDirectory.getStr()) == -1)
 //#endif
-            {
-                fprintf(stderr, "%s: cannot remove directory '%s'\n",
-                        idlc()->getOptions()->getProgramName().getStr(), createdDirectory.getStr());
-                return false;
-            }
+        {
+            fprintf(stderr, "%s: cannot remove directory '%s'\n",
+                    idlc()->getOptions()->getProgramName().getStr(), createdDirectory.getStr());
+            return false;
         }
-        delete pCreatedDirectories;
     }
+    gaCreatedDirectories.clear();
     return true;
 }
 
diff --git a/sal/rtl/locale.cxx b/sal/rtl/locale.cxx
index bae0f40b3d66..742041ac1579 100644
--- a/sal/rtl/locale.cxx
+++ b/sal/rtl/locale.cxx
@@ -43,23 +43,17 @@ struct locale_deleter
 
 using locale_unique_ptr = std::unique_ptr<rtl_Locale, locale_deleter>;
 
-static std::unordered_map<sal_Int32, locale_unique_ptr>* g_pLocaleTable = nullptr;
+static std::unordered_map<sal_Int32, locale_unique_ptr> g_aLocaleTable;
 
 static rtl_Locale* g_pDefaultLocale = nullptr;
 
 void rtl_locale_init()
 {
-    if (!g_pLocaleTable)
-        g_pLocaleTable = new std::unordered_map<sal_Int32, locale_unique_ptr>;
 }
 
 void rtl_locale_fini()
 {
-    if (g_pLocaleTable)
-    {
-        delete g_pLocaleTable;
-        g_pLocaleTable = nullptr;
-    }
+    g_aLocaleTable.clear();
     g_pDefaultLocale = nullptr;
 }
 
@@ -81,8 +75,8 @@ rtl_Locale * SAL_CALL rtl_locale_register(const sal_Unicode * language, const sa
 
     hashCode = rtl_ustr_hashCode(language) ^ rtl_ustr_hashCode(country) ^ rtl_ustr_hashCode(variant);
 
-    auto it = g_pLocaleTable->find(hashCode);
-    if (it != g_pLocaleTable->end())
+    auto it = g_aLocaleTable.find(hashCode);
+    if (it != g_aLocaleTable.end())
         return it->second.get();
 
     rtl_uString_newFromStr(&sLanguage, language);
@@ -97,7 +91,7 @@ rtl_Locale * SAL_CALL rtl_locale_register(const sal_Unicode * language, const sa
     newLocale->HashCode = hashCode;
 
     auto ret = newLocale.get();
-    g_pLocaleTable->insert(it, std::pair<sal_Int32, locale_unique_ptr>( hashCode, std::move(newLocale) ) );
+    g_aLocaleTable.insert(it, std::pair<sal_Int32, locale_unique_ptr>( hashCode, std::move(newLocale) ) );
     return ret;
 }
 
diff --git a/sfx2/source/view/frame.cxx b/sfx2/source/view/frame.cxx
index a99e9dead483..3c3b68f0a628 100644
--- a/sfx2/source/view/frame.cxx
+++ b/sfx2/source/view/frame.cxx
@@ -51,7 +51,7 @@
 
 using namespace com::sun::star;
 
-static std::vector<SfxFrame*>* pFramesArr_Impl=nullptr;
+static std::vector<SfxFrame*> gaFramesArr_Impl;
 
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::util;
@@ -71,9 +71,7 @@ SfxPoolItem* SfxUnoFrameItem::CreateDefault()
 void SfxFrame::Construct_Impl()
 {
     pImpl.reset(new SfxFrame_Impl);
-    if ( !pFramesArr_Impl )
-        pFramesArr_Impl = new std::vector<SfxFrame*>;
-    pFramesArr_Impl->push_back( this );
+    gaFramesArr_Impl.push_back( this );
 }
 
 
@@ -82,9 +80,9 @@ SfxFrame::~SfxFrame()
     RemoveTopFrame_Impl( this );
     pWindow.disposeAndClear();
 
-    auto it = std::find( pFramesArr_Impl->begin(), pFramesArr_Impl->end(), this );
-    if ( it != pFramesArr_Impl->end() )
-        pFramesArr_Impl->erase( it );
+    auto it = std::find( gaFramesArr_Impl.begin(), gaFramesArr_Impl.end(), this );
+    if ( it != gaFramesArr_Impl.end() )
+        gaFramesArr_Impl.erase( it );
 
     delete pImpl->pDescr;
 }
@@ -717,15 +715,13 @@ void SfxFrame::Resize()
 
 SfxFrame* SfxFrame::GetFirst()
 {
-    if ( !pFramesArr_Impl )
-        return nullptr;
-    return pFramesArr_Impl->empty() ? nullptr : pFramesArr_Impl->front();
+    return gaFramesArr_Impl.empty() ? nullptr : gaFramesArr_Impl.front();
 }
 
 SfxFrame* SfxFrame::GetNext( SfxFrame& rFrame )
 {
-    auto it = std::find( pFramesArr_Impl->begin(), pFramesArr_Impl->end(), &rFrame );
-    if ( it != pFramesArr_Impl->end() && (++it) != pFramesArr_Impl->end() )
+    auto it = std::find( gaFramesArr_Impl.begin(), gaFramesArr_Impl.end(), &rFrame );
+    if ( it != gaFramesArr_Impl.end() && (++it) != gaFramesArr_Impl.end() )
         return *it;
     else
         return nullptr;
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index b9b5b4fb2f20..754176787abc 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -496,7 +496,7 @@ struct ImageCacheItem
 // LRU cache, last item is the least recently used. Hopefully there won't be that many items
 // to require a hash/map. Using o3tl::lru_cache would be simpler, but it doesn't support
 // calculating cost of each item.
-static std::list<ImageCacheItem>* imageCache = nullptr;
+static std::list<ImageCacheItem> imageCache;
 static tools::Long imageCacheSize = 0; // sum of all ImageCacheItem.size
 
 void addCachedImage(const OString& key, sk_sp<SkImage> image)
@@ -504,38 +504,32 @@ void addCachedImage(const OString& key, sk_sp<SkImage> image)
     static bool disabled = getenv("SAL_DISABLE_SKIA_CACHE") != nullptr;
     if (disabled)
         return;
-    if (imageCache == nullptr)
-        imageCache = new std::list<ImageCacheItem>;
     tools::Long size = static_cast<tools::Long>(image->width()) * image->height()
                        * SkColorTypeBytesPerPixel(image->imageInfo().colorType());
-    imageCache->push_front({ key, image, size });
+    imageCache.push_front({ key, image, size });
     imageCacheSize += size;
     SAL_INFO("vcl.skia.trace", "addcachedimage " << image << " :" << size << "/" << imageCacheSize);
     const tools::Long maxSize = maxImageCacheSize();
     while (imageCacheSize > maxSize)
     {
-        assert(!imageCache->empty());
-        imageCacheSize -= imageCache->back().size;
-        SAL_INFO("vcl.skia.trace", "least used removal " << imageCache->back().image << ":"
-                                                         << imageCache->back().size);
-        imageCache->pop_back();
+        assert(!imageCache.empty());
+        imageCacheSize -= imageCache.back().size;
+        SAL_INFO("vcl.skia.trace",
+                 "least used removal " << imageCache.back().image << ":" << imageCache.back().size);
+        imageCache.pop_back();
     }
 }
 
 sk_sp<SkImage> findCachedImage(const OString& key)
 {
-    if (imageCache != nullptr)
+    for (auto it = imageCache.begin(); it != imageCache.end(); ++it)
     {
-        for (auto it = imageCache->begin(); it != imageCache->end(); ++it)
+        if (it->key == key)
         {
-            if (it->key == key)
-            {
-                sk_sp<SkImage> ret = it->image;
-                SAL_INFO("vcl.skia.trace",
-                         "findcachedimage " << key << " : " << it->image << " found");
-                imageCache->splice(imageCache->begin(), *imageCache, it);
-                return ret;
-            }
+            sk_sp<SkImage> ret = it->image;
+            SAL_INFO("vcl.skia.trace", "findcachedimage " << key << " : " << it->image << " found");
+            imageCache.splice(imageCache.begin(), imageCache, it);
+            return ret;
         }
     }
     SAL_INFO("vcl.skia.trace", "findcachedimage " << key << " not found");
@@ -544,15 +538,13 @@ sk_sp<SkImage> findCachedImage(const OString& key)
 
 void removeCachedImage(sk_sp<SkImage> image)
 {
-    if (imageCache == nullptr)
-        return;
-    for (auto it = imageCache->begin(); it != imageCache->end();)
+    for (auto it = imageCache.begin(); it != imageCache.end();)
     {
         if (it->image == image)
         {
             imageCacheSize -= it->size;
             assert(imageCacheSize >= 0);
-            it = imageCache->erase(it);
+            it = imageCache.erase(it);
         }
         else
             ++it;
@@ -569,8 +561,7 @@ void cleanup()
 {
     delete sharedGrDirectContext;
     sharedGrDirectContext = nullptr;
-    delete imageCache;
-    imageCache = nullptr;
+    imageCache.clear();
     imageCacheSize = 0;
 }
 


More information about the Libreoffice-commits mailing list