[Libreoffice-commits] core.git: desktop/source drawinglayer/source include/vcl sd/source svx/source sw/source vcl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 22 08:16:26 UTC 2021


 desktop/source/lib/lokclipboard.cxx                       |    3 -
 drawinglayer/source/processor2d/vclhelperbufferdevice.cxx |    2 -
 include/vcl/lazydelete.hxx                                |   27 +++++++++++---
 sd/source/ui/view/viewoverlaymanager.cxx                  |    8 ++--
 svx/source/sdr/contact/viewcontactofsdrpage.cxx           |    3 -
 svx/source/sdr/primitive2d/sdrprimitivetools.cxx          |    4 +-
 svx/source/svdraw/svdhdl.cxx                              |    2 -
 sw/source/core/layout/paintfrm.cxx                        |   19 ++++-----
 sw/source/core/txtnode/fntcache.cxx                       |    2 -
 sw/source/core/view/viewsh.cxx                            |    2 -
 vcl/source/outdev/textline.cxx                            |    2 -
 11 files changed, 44 insertions(+), 30 deletions(-)

New commits:
commit 88c85c8aa377ccc017582d8a08e5f73391b5a446
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jul 21 08:47:42 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jul 22 10:15:49 2021 +0200

    flatten vcl::LazyDelete
    
    we can allocate the stored value in-line and avoid some pointer-chasing
    
    Change-Id: I828814b127923cdcec1bf57b3b64dffab4cffaaf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119298
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx
index c70c8f0ed750..193c74472ba4 100644
--- a/desktop/source/lib/lokclipboard.cxx
+++ b/desktop/source/lib/lokclipboard.cxx
@@ -18,8 +18,7 @@ using namespace css;
 using namespace css::uno;
 
 /* static */ osl::Mutex LOKClipboardFactory::gMutex;
-static vcl::DeleteOnDeinit<std::unordered_map<int, rtl::Reference<LOKClipboard>>>
-gClipboards(new std::unordered_map<int, rtl::Reference<LOKClipboard>>);
+static vcl::DeleteOnDeinit<std::unordered_map<int, rtl::Reference<LOKClipboard>>> gClipboards{};
 
 rtl::Reference<LOKClipboard> LOKClipboardFactory::getClipboardForCurView()
 {
diff --git a/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx b/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
index f6bf0f10c9f7..a0e29d7e6942 100644
--- a/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
+++ b/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
@@ -264,7 +264,7 @@ VDevBuffer& getVDevBuffer()
     // secure global instance with Vcl's safe destroyer of external (seen by
     // library base) stuff, the remembered VDevs need to be deleted before
     // Vcl's deinit
-    static vcl::DeleteOnDeinit<VDevBuffer> aVDevBuffer(new VDevBuffer());
+    static vcl::DeleteOnDeinit<VDevBuffer> aVDevBuffer{};
     return *aVDevBuffer.get();
 }
 
diff --git a/include/vcl/lazydelete.hxx b/include/vcl/lazydelete.hxx
index 1e253e54ee1d..397bde8838a8 100644
--- a/include/vcl/lazydelete.hxx
+++ b/include/vcl/lazydelete.hxx
@@ -24,7 +24,7 @@
 
 #include <com/sun/star/lang/XComponent.hpp>
 
-#include <memory>
+#include <optional>
 
 namespace vcl
 {
@@ -64,20 +64,37 @@ namespace vcl
         virtual void doCleanup() = 0;
     };
 
+    enum class DeleteOnDeinitFlag { Empty };
+
     template < typename T >
     class DeleteOnDeinit final : public DeleteOnDeinitBase
     {
-        std::unique_ptr<T> m_pT;
+        std::optional<T> m_pT;
         virtual void doCleanup() override { m_pT.reset(); }
     public:
-        DeleteOnDeinit( T* i_pT ) : m_pT( i_pT ) { addDeinitContainer( this ); }
+        template <class... Args >
+        DeleteOnDeinit(Args&&... args )
+        {
+            m_pT.emplace(args...);
+            addDeinitContainer( this );
+        }
+        DeleteOnDeinit(DeleteOnDeinitFlag)
+        {
+            addDeinitContainer( this );
+        }
 
         // get contents
-        T* get() { return m_pT.get(); }
+        T* get() { return m_pT ? &*m_pT : nullptr; }
 
         // set contents, returning old contents
         // ownership is transferred !
-        std::unique_ptr<T> set( std::unique_ptr<T> i_pNew ) { auto pOld = std::move(m_pT); m_pT = std::move(i_pNew); return pOld; }
+        template <class... Args >
+        std::optional<T> set(Args&&... args)
+        {
+            auto pOld = std::move(m_pT);
+            m_pT.emplace(args...);
+            return pOld;
+        }
     };
 
     /** Similar to DeleteOnDeinit, the DeleteUnoReferenceOnDeinit
diff --git a/sd/source/ui/view/viewoverlaymanager.cxx b/sd/source/ui/view/viewoverlaymanager.cxx
index 3e7f187ea506..d1db1e73a194 100644
--- a/sd/source/ui/view/viewoverlaymanager.cxx
+++ b/sd/source/ui/view/viewoverlaymanager.cxx
@@ -90,8 +90,8 @@ const std::u16string_view aBigPlaceHolders[] =
 
 static BitmapEx* getButtonImage( int index, bool large )
 {
-    static vcl::DeleteOnDeinit< BitmapEx > gSmallButtonImages[SAL_N_ELEMENTS(aSmallPlaceHolders)] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
-    static vcl::DeleteOnDeinit< BitmapEx > gLargeButtonImages[SAL_N_ELEMENTS(aBigPlaceHolders)] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
+    static vcl::DeleteOnDeinit< BitmapEx > gSmallButtonImages[SAL_N_ELEMENTS(aSmallPlaceHolders)] = { vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty };
+    static vcl::DeleteOnDeinit< BitmapEx > gLargeButtonImages[SAL_N_ELEMENTS(aBigPlaceHolders)] = { vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty };
 
     assert(SAL_N_ELEMENTS(aSmallPlaceHolders) == SAL_N_ELEMENTS(aBigPlaceHolders));
 
@@ -99,8 +99,8 @@ static BitmapEx* getButtonImage( int index, bool large )
     {
         for (size_t i = 0; i < SAL_N_ELEMENTS(aSmallPlaceHolders); i++ )
         {
-            gSmallButtonImages[i].set(std::make_unique<BitmapEx>(OUString(aSmallPlaceHolders[i])));
-            gLargeButtonImages[i].set(std::make_unique<BitmapEx>(OUString(aBigPlaceHolders[i])));
+            gSmallButtonImages[i].set(OUString(aSmallPlaceHolders[i]));
+            gLargeButtonImages[i].set(OUString(aBigPlaceHolders[i]));
         }
     }
 
diff --git a/svx/source/sdr/contact/viewcontactofsdrpage.cxx b/svx/source/sdr/contact/viewcontactofsdrpage.cxx
index 19911ed53440..d2fab00075fc 100644
--- a/svx/source/sdr/contact/viewcontactofsdrpage.cxx
+++ b/svx/source/sdr/contact/viewcontactofsdrpage.cxx
@@ -136,8 +136,7 @@ drawinglayer::primitive2d::Primitive2DContainer ViewContactOfPageShadow::createV
     else
     {
         static vcl::DeleteOnDeinit< drawinglayer::primitive2d::DiscreteShadow > aDiscreteShadow(
-            new drawinglayer::primitive2d::DiscreteShadow(
-                BitmapEx(SIP_SA_PAGESHADOW35X35)));
+                BitmapEx(SIP_SA_PAGESHADOW35X35));
 
         if(aDiscreteShadow.get())
         {
diff --git a/svx/source/sdr/primitive2d/sdrprimitivetools.cxx b/svx/source/sdr/primitive2d/sdrprimitivetools.cxx
index 2ad11a523034..cf215a141b11 100644
--- a/svx/source/sdr/primitive2d/sdrprimitivetools.cxx
+++ b/svx/source/sdr/primitive2d/sdrprimitivetools.cxx
@@ -29,7 +29,7 @@ namespace drawinglayer::primitive2d
 {
         BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
         {
-            static vcl::DeleteOnDeinit< BitmapEx > aRetVal(nullptr);
+            static vcl::DeleteOnDeinit< BitmapEx > aRetVal(vcl::DeleteOnDeinitFlag::Empty);
             static basegfx::BColor aBColor;
             static ::osl::Mutex aMutex;
 
@@ -54,7 +54,7 @@ namespace drawinglayer::primitive2d
                 BitmapEx aBitmap = vcl::bitmap::CreateFromData(cross, 3, 3, 12, vcl::PixelFormat::N32_BPP);
 
                 // create and exchange at aRetVal
-                aRetVal.set(std::make_unique<BitmapEx>(aBitmap));
+                aRetVal.set(aBitmap);
             }
 
             return aRetVal.get() ? *aRetVal.get() : BitmapEx();
diff --git a/svx/source/svdraw/svdhdl.cxx b/svx/source/svdraw/svdhdl.cxx
index 339f3d638f55..92a68e5ada58 100644
--- a/svx/source/svdraw/svdhdl.cxx
+++ b/svx/source/svdraw/svdhdl.cxx
@@ -773,7 +773,7 @@ BitmapEx ImpGetBitmapEx(BitmapMarkerKind eKindOfMarker, BitmapColorIndex eIndex)
 
     // if we can't load the marker...
 
-    static vcl::DeleteOnDeinit< SdrHdlBitmapSet > aModernSet(new SdrHdlBitmapSet);
+    static vcl::DeleteOnDeinit< SdrHdlBitmapSet > aModernSet {};
     return aModernSet.get()->GetBitmapEx(eKindOfMarker, sal_uInt16(eIndex));
 }
 
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index c42afecddd77..0155ceb08a30 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -5911,19 +5911,18 @@ static void lcl_paintBitmapExToRect(vcl::RenderContext *pOut, const Point& aPoin
     SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, *_pViewShell->GetOut() );
 
     static vcl::DeleteOnDeinit<drawinglayer::primitive2d::DiscreteShadow> shadowMaskObj(
-        new drawinglayer::primitive2d::DiscreteShadow(
             vcl::bitmap::loadFromName(BMP_PAGE_SHADOW_MASK,
-                                      ImageLoadFlags::IgnoreDarkTheme | ImageLoadFlags::IgnoreScalingFactor)));
+                                      ImageLoadFlags::IgnoreDarkTheme | ImageLoadFlags::IgnoreScalingFactor));
 
     drawinglayer::primitive2d::DiscreteShadow& shadowMask = *shadowMaskObj.get();
-    static vcl::DeleteOnDeinit< BitmapEx > aPageTopRightShadowObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageBottomRightShadowObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageBottomLeftShadowObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageBottomShadowBaseObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageRightShadowBaseObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageTopShadowBaseObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageTopLeftShadowObj( new BitmapEx );
-    static vcl::DeleteOnDeinit< BitmapEx > aPageLeftShadowBaseObj( new BitmapEx );
+    static vcl::DeleteOnDeinit< BitmapEx > aPageTopRightShadowObj {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageBottomRightShadowObj {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageBottomLeftShadowObj  {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageBottomShadowBaseObj  {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageRightShadowBaseObj  {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageTopShadowBaseObj  {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageTopLeftShadowObj  {};
+    static vcl::DeleteOnDeinit< BitmapEx > aPageLeftShadowBaseObj  {};
     BitmapEx& aPageTopRightShadow = *aPageTopRightShadowObj.get();
     BitmapEx& aPageBottomRightShadow = *aPageBottomRightShadowObj.get();
     BitmapEx& aPageBottomLeftShadow = *aPageBottomLeftShadowObj.get();
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 1da7a73acdee..9ceb04851ba1 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -69,7 +69,7 @@ constexpr Color gWaveCol(COL_GRAY);
 
 tools::Long SwFntObj::s_nPixWidth;
 MapMode* SwFntObj::s_pPixMap = nullptr;
-static vcl::DeleteOnDeinit< VclPtr<OutputDevice> > s_pFntObjPixOut( new VclPtr<OutputDevice> );
+static vcl::DeleteOnDeinit< VclPtr<OutputDevice> > s_pFntObjPixOut {};
 
 /**
  * Defines a substring on a given output device, to be used as an std::map<>
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index ff59a3b58c01..32a9332f1632 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -85,7 +85,7 @@
 
 bool SwViewShell::sbLstAct = false;
 ShellResource *SwViewShell::spShellRes = nullptr;
-vcl::DeleteOnDeinit<std::shared_ptr<weld::Window>> SwViewShell::spCareDialog(new std::shared_ptr<weld::Window>);
+vcl::DeleteOnDeinit<std::shared_ptr<weld::Window>> SwViewShell::spCareDialog {};
 
 static bool bInSizeNotify = false;
 
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 8b22aa8fb847..7d78f30fe326 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -1067,7 +1067,7 @@ void OutputDevice::DrawWaveLine(const Point& rStartPos, const Point& rEndPos, to
 
     if ( fOrientation == 0.0 )
     {
-        static vcl::DeleteOnDeinit< WavyLineCache > snLineCache( new WavyLineCache() );
+        static vcl::DeleteOnDeinit< WavyLineCache > snLineCache {};
         if ( !snLineCache.get() )
             return;
         WavyLineCache& rLineCache = *snLineCache.get();


More information about the Libreoffice-commits mailing list