diff options
author | Eike Rathke <erack@redhat.com> | 2017-02-27 22:24:14 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-02-27 22:29:54 +0100 |
commit | d5d220b47416660b2f8cc370b2d2d1baf11c77ec (patch) | |
tree | c0a22126edefe9e5334ba540206646812a2b9e23 /sc | |
parent | b5c83cf676541d367ea4d0ce0c5531160f2b215b (diff) |
move assign() into operator=() and add the relevant bits to copy-ctor
Change-Id: Iac606a8e5e4fc9beb019d95d2a05f0ab9d9dad34
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/postit.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/postit.cxx | 56 |
2 files changed, 31 insertions, 28 deletions
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx index ad671fb649c2..f7c10daab2d7 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 747eb68dcfc7..e7004e7835e6 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 { |