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

Takeshi Abe tabe at fixedpoint.jp
Tue Oct 3 06:49:06 UTC 2017


 include/svx/svdglue.hxx       |   17 ++++++----------
 svx/source/svdraw/svdglue.cxx |   44 ++++++++++++++----------------------------
 2 files changed, 22 insertions(+), 39 deletions(-)

New commits:
commit 445b17ce332007a62cd1e4f6eac4d337896c68b2
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Sep 28 12:22:12 2017 +0900

    svx: Simplify SdrGluePointList with std::unique_ptr
    
    This also inlines SdrGluePointList::GetObject().
    
    Change-Id: I70052a5e94b3451f5a00e1185e6dee59e5537184
    Reviewed-on: https://gerrit.libreoffice.org/43059
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/svdglue.hxx b/include/svx/svdglue.hxx
index 1db3ca9acce9..0a74ef8e5127 100644
--- a/include/svx/svdglue.hxx
+++ b/include/svx/svdglue.hxx
@@ -22,6 +22,7 @@
 
 #include <tools/gen.hxx>
 #include <svx/svxdllapi.h>
+#include <memory>
 #include <vector>
 #include <o3tl/typed_flags_set.hxx>
 
@@ -115,13 +116,11 @@ public:
 #define SDRGLUEPOINT_NOTFOUND 0xFFFF
 
 class SVX_DLLPUBLIC SdrGluePointList {
-    std::vector<SdrGluePoint*> aList;
-protected:
-    SdrGluePoint* GetObject(sal_uInt16 i) const { return aList[i]; }
+    std::vector<std::unique_ptr<SdrGluePoint>> aList;
 public:
-    SdrGluePointList(): aList() {}
-    SdrGluePointList(const SdrGluePointList& rSrcList): aList()     { *this=rSrcList; }
-    ~SdrGluePointList()                                                     { Clear(); }
+    SdrGluePointList() {};
+    SdrGluePointList(const SdrGluePointList& rSrcList) { *this=rSrcList; }
+
     void                Clear();
     SdrGluePointList&   operator=(const SdrGluePointList& rSrcList);
     sal_uInt16          GetCount() const                                    { return sal_uInt16(aList.size()); }
@@ -130,12 +129,10 @@ public:
     sal_uInt16          Insert(const SdrGluePoint& rGP);
     void                Delete(sal_uInt16 nPos)
     {
-        SdrGluePoint* p = aList[nPos];
         aList.erase(aList.begin()+nPos);
-        delete p;
     }
-    SdrGluePoint&       operator[](sal_uInt16 nPos)                             { return *GetObject(nPos); }
-    const SdrGluePoint& operator[](sal_uInt16 nPos) const                       { return *GetObject(nPos); }
+    SdrGluePoint&       operator[](sal_uInt16 nPos)                             { return *aList[nPos]; }
+    const SdrGluePoint& operator[](sal_uInt16 nPos) const                       { return *aList[nPos]; }
     sal_uInt16          FindGluePoint(sal_uInt16 nId) const;
     sal_uInt16          HitTest(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj) const;
     void                Invalidate(vcl::Window& rWin, const SdrObject* pObj) const;
diff --git a/svx/source/svdraw/svdglue.cxx b/svx/source/svdraw/svdglue.cxx
index 835adc1c8205..d8f6f9e4a31b 100644
--- a/svx/source/svdraw/svdglue.cxx
+++ b/svx/source/svdraw/svdglue.cxx
@@ -278,10 +278,6 @@ bool SdrGluePoint::IsHit(const Point& rPnt, const OutputDevice& rOut, const SdrO
 
 void SdrGluePointList::Clear()
 {
-    sal_uInt16 nCount=GetCount();
-    for (sal_uInt16 i=0; i<nCount; i++) {
-        delete GetObject(i);
-    }
     aList.clear();
 }
 
@@ -303,7 +299,7 @@ sal_uInt16 SdrGluePointList::Insert(const SdrGluePoint& rGP)
     sal_uInt16 nId=pGP->GetId();
     sal_uInt16 nCount=GetCount();
     sal_uInt16 nInsPos=nCount;
-    sal_uInt16 nLastId=nCount!=0 ? GetObject(nCount-1)->GetId() : 0;
+    sal_uInt16 nLastId=nCount!=0 ? aList[nCount-1]->GetId() : 0;
     DBG_ASSERT(nLastId>=nCount,"SdrGluePointList::Insert(): nLastId<nCount");
     bool bHole = nLastId>nCount;
     if (nId<=nLastId) {
@@ -312,7 +308,7 @@ sal_uInt16 SdrGluePointList::Insert(const SdrGluePoint& rGP)
         } else {
             bool bBrk = false;
             for (sal_uInt16 nNum=0; nNum<nCount && !bBrk; nNum++) {
-                const SdrGluePoint* pGP2=GetObject(nNum);
+                const auto& pGP2=aList[nNum];
                 sal_uInt16 nTmpId=pGP2->GetId();
                 if (nTmpId==nId) {
                     nId=nLastId+1; // already in use
@@ -326,16 +322,14 @@ sal_uInt16 SdrGluePointList::Insert(const SdrGluePoint& rGP)
         }
         pGP->SetId(nId);
     }
-    aList.insert(aList.begin()+nInsPos, pGP);
+    aList.emplace(aList.begin()+nInsPos, pGP);
     return nInsPos;
 }
 
 void SdrGluePointList::Invalidate(vcl::Window& rWin, const SdrObject* pObj) const
 {
-    sal_uInt16 nCount=GetCount();
-    for (sal_uInt16 nNum=0; nNum<nCount; nNum++) {
-        GetObject(nNum)->Invalidate(rWin,pObj);
-    }
+    for (auto& xGP : aList)
+        xGP->Invalidate(rWin,pObj);
 }
 
 sal_uInt16 SdrGluePointList::FindGluePoint(sal_uInt16 nId) const
@@ -345,7 +339,7 @@ sal_uInt16 SdrGluePointList::FindGluePoint(sal_uInt16 nId) const
     sal_uInt16 nCount=GetCount();
     sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
     for (sal_uInt16 nNum=0; nNum<nCount && nRet==SDRGLUEPOINT_NOTFOUND; nNum++) {
-        const SdrGluePoint* pGP=GetObject(nNum);
+        const auto& pGP=aList[nNum];
         if (pGP->GetId()==nId) nRet=nNum;
     }
     return nRet;
@@ -358,7 +352,7 @@ sal_uInt16 SdrGluePointList::HitTest(const Point& rPnt, const OutputDevice& rOut
     sal_uInt16 nNum = nCount;
     while ((nNum>0) && nRet==SDRGLUEPOINT_NOTFOUND) {
         nNum--;
-        const SdrGluePoint* pGP = GetObject(nNum);
+        const auto& pGP = aList[nNum];
         if (pGP->IsHit(rPnt,rOut,pObj))
             nRet = nNum;
     }
@@ -367,18 +361,14 @@ sal_uInt16 SdrGluePointList::HitTest(const Point& rPnt, const OutputDevice& rOut
 
 void SdrGluePointList::SetReallyAbsolute(bool bOn, const SdrObject& rObj)
 {
-    sal_uInt16 nCount=GetCount();
-    for (sal_uInt16 nNum=0; nNum<nCount; nNum++) {
-        GetObject(nNum)->SetReallyAbsolute(bOn,rObj);
-    }
+    for (auto& xGP : aList)
+        xGP->SetReallyAbsolute(bOn,rObj);
 }
 
 void SdrGluePointList::Rotate(const Point& rRef, long nAngle, double sn, double cs, const SdrObject* pObj)
 {
-    sal_uInt16 nCount=GetCount();
-    for (sal_uInt16 nNum=0; nNum<nCount; nNum++) {
-        GetObject(nNum)->Rotate(rRef,nAngle,sn,cs,pObj);
-    }
+    for (auto& xGP : aList)
+        xGP->Rotate(rRef,nAngle,sn,cs,pObj);
 }
 
 void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj)
@@ -390,18 +380,14 @@ void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, const SdrO
 
 void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, long nAngle, const SdrObject* pObj)
 {
-    sal_uInt16 nCount=GetCount();
-    for (sal_uInt16 nNum=0; nNum<nCount; nNum++) {
-        GetObject(nNum)->Mirror(rRef1,rRef2,nAngle,pObj);
-    }
+    for (auto& xGP : aList)
+        xGP->Mirror(rRef1,rRef2,nAngle,pObj);
 }
 
 void SdrGluePointList::Shear(const Point& rRef, double tn, bool bVShear, const SdrObject* pObj)
 {
-    sal_uInt16 nCount=GetCount();
-    for (sal_uInt16 nNum=0; nNum<nCount; nNum++) {
-        GetObject(nNum)->Shear(rRef,tn,bVShear,pObj);
-    }
+    for (auto& xGP : aList)
+        xGP->Shear(rRef,tn,bVShear,pObj);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list