[Libreoffice-commits] core.git: svx/inc svx/source

Noel Grandin noel.grandin at collabora.co.uk
Wed Apr 19 09:06:04 UTC 2017


 svx/inc/sdr/properties/itemsettools.hxx    |    7 +++++--
 svx/source/sdr/properties/itemsettools.cxx |   17 ++++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)

New commits:
commit d9e6002b70eadd47fe70ff5ef53a55e5fa32d846
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 13 12:04:36 2017 +0200

    use union instead of void*
    
    vaguely more readable and typesafe
    
    Change-Id: I15e98034fb288756415913eff73bcaba4f2c0b9d
    Reviewed-on: https://gerrit.libreoffice.org/36659
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svx/inc/sdr/properties/itemsettools.hxx b/svx/inc/sdr/properties/itemsettools.hxx
index 0e1f760e0777..c9cb93261ad0 100644
--- a/svx/inc/sdr/properties/itemsettools.hxx
+++ b/svx/inc/sdr/properties/itemsettools.hxx
@@ -36,7 +36,10 @@ namespace sdr
         class ItemChangeBroadcaster
         {
             bool                                            mbSingleRect;
-            void*                                           mpData;
+            union {
+                RectangleVector*                            mpRectangleVector;
+                tools::Rectangle*                           mpRectangle;
+            };
 
         public:
             explicit ItemChangeBroadcaster(const SdrObject& rObj);
@@ -44,7 +47,7 @@ namespace sdr
 
             sal_uInt32 GetRectangleCount() const
             {
-                return mbSingleRect ? 1 : static_cast<RectangleVector*>(mpData)->size();
+                return mbSingleRect ? 1 : mpRectangleVector->size();
             }
             const tools::Rectangle& GetRectangle(sal_uInt32 nIndex) const;
         };
diff --git a/svx/source/sdr/properties/itemsettools.cxx b/svx/source/sdr/properties/itemsettools.cxx
index b3cc64875edc..c11c54dcf445 100644
--- a/svx/source/sdr/properties/itemsettools.cxx
+++ b/svx/source/sdr/properties/itemsettools.cxx
@@ -38,9 +38,8 @@ namespace sdr
             if (const SdrObjGroup* pGroupObj = dynamic_cast<const SdrObjGroup*>(&rObj))
             {
                 SdrObjListIter aIter(*pGroupObj, SdrIterMode::DeepNoGroups);
-                mpData = new RectangleVector;
-                DBG_ASSERT(mpData, "ItemChangeBroadcaster: No memory (!)");
-                static_cast<RectangleVector*>(mpData)->reserve(aIter.Count());
+                mpRectangleVector = new RectangleVector;
+                mpRectangleVector->reserve(aIter.Count());
 
                 while(aIter.IsMore())
                 {
@@ -48,7 +47,7 @@ namespace sdr
 
                     if(pObj)
                     {
-                        static_cast<RectangleVector*>(mpData)->push_back(pObj->GetLastBoundRect());
+                        mpRectangleVector->push_back(pObj->GetLastBoundRect());
                     }
                 }
 
@@ -56,7 +55,7 @@ namespace sdr
             }
             else
             {
-                mpData = new tools::Rectangle(rObj.GetLastBoundRect());
+                mpRectangle = new tools::Rectangle(rObj.GetLastBoundRect());
                 mbSingleRect = true;
             }
         }
@@ -65,11 +64,11 @@ namespace sdr
         {
             if (!mbSingleRect)
             {
-                delete static_cast<RectangleVector*>(mpData);
+                delete mpRectangleVector;
             }
             else
             {
-                delete static_cast<tools::Rectangle*>(mpData);
+                delete mpRectangle;
             }
         }
 
@@ -77,11 +76,11 @@ namespace sdr
         {
             if (!mbSingleRect)
             {
-                return (*static_cast<RectangleVector*>(mpData))[nIndex];
+                return (*mpRectangleVector)[nIndex];
             }
             else
             {
-                return *static_cast<tools::Rectangle*>(mpData);
+                return *mpRectangle;
             }
         }
     } // end of namespace properties


More information about the Libreoffice-commits mailing list