sc/inc/postit.hxx              |    3 --
 sc/source/core/data/postit.cxx |   56 ++++++++++++++++++++++-------------------
 2 files changed, 31 insertions(+), 28 deletions(-)

New commits:
commit d5d220b47416660b2f8cc370b2d2d1baf11c77ec
Author: Eike Rathke <er...@redhat.com>
Date:   Mon Feb 27 22:24:14 2017 +0100

    move assign() into operator=() and add the relevant bits to copy-ctor
    
    Change-Id: Iac606a8e5e4fc9beb019d95d2a05f0ab9d9dad34

diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index ad671fb..f7c10da 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -88,9 +88,6 @@ private:
     bool decRef() const;        //< @returns <TRUE/> if the last reference was 
decremented.
     void decRefAndDestroy();    //< Destroys caption object if the last 
reference was decremented.
 
-    /** Operations common to ctor and assignment operator, maintaining the 
lists. */
-    void assign( const ScCaptionPtr& r, bool bAssignment );
-
     /** Remove from current list and close gap.
 
         Usually there are only very few instances, so maintaining a doubly
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 747eb68..e7004e7 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -459,21 +459,28 @@ ScCaptionPtr::ScCaptionPtr( SdrCaptionObj* p ) :
 }
 
 ScCaptionPtr::ScCaptionPtr( const ScCaptionPtr& r ) :
-    mpHead(nullptr), mpNext(nullptr), mpCaption(nullptr)
+    mpHead(r.mpHead), mpCaption(r.mpCaption)
 {
-    assign( r, false);
+    if (r.mpCaption)
+    {
+        assert(r.mpHead);
+        r.incRef();
+        // Insert into list.
+        mpNext = r.mpNext;
+        r.mpNext = this;
+    }
+    else
+    {
+        assert(!r.mpHead);
+        mpNext = nullptr;
+    }
 }
 
-void ScCaptionPtr::newHead()
+ScCaptionPtr& ScCaptionPtr::operator=( const ScCaptionPtr& r )
 {
-    assert(!mpHead);
-    mpHead = new Head;
-    mpHead->mpFirst = this;
-    mpHead->mnRefs = 1;
-}
+    if (this == &r)
+        return *this;
 
-void ScCaptionPtr::assign( const ScCaptionPtr& r, bool bAssignment )
-{
     if (mpCaption == r.mpCaption)
     {
         // Two lists for the same caption is bad.
@@ -481,7 +488,7 @@ void ScCaptionPtr::assign( const ScCaptionPtr& r, bool 
bAssignment )
         assert(!mpCaption);     // assigning same caption pointer within same 
list is weird
         // Nullptr captions are not inserted to the list, so nothing to do here
         // if both are.
-        return;
+        return *this;
     }
 
     // Let's find some weird usage.
@@ -491,17 +498,25 @@ void ScCaptionPtr::assign( const ScCaptionPtr& r, bool 
bAssignment )
     assert(r.mpHead != mpHead);
 
     r.incRef();
-    if (bAssignment)
-    {
-        decRefAndDestroy();
-        removeFromList();
-    }
+    decRefAndDestroy();
+    removeFromList();
+
     mpCaption = r.mpCaption;
     // That head is this' master.
     mpHead = r.mpHead;
     // Insert into list.
     mpNext = r.mpNext;
     r.mpNext = this;
+
+    return *this;
+}
+
+void ScCaptionPtr::newHead()
+{
+    assert(!mpHead);
+    mpHead = new Head;
+    mpHead->mpFirst = this;
+    mpHead->mnRefs = 1;
 }
 
 void ScCaptionPtr::removeFromList()
@@ -666,15 +681,6 @@ void ScCaptionPtr::clear()
     mpCaption = nullptr;
 }
 
-ScCaptionPtr& ScCaptionPtr::operator=( const ScCaptionPtr& r )
-{
-    if (this == &r)
-        return *this;
-
-    assign( r, true);
-    return *this;
-}
-
 
 struct ScCaptionInitData
 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to