summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-02-27 22:24:14 +0100
committerJan Holesovsky <kendy@collabora.com>2017-05-15 21:58:53 +0200
commit344dd43b3f790d44abfb4c0addc4378b827a7fe1 (patch)
treeddf9acc74e65b25e4b38c609f4ab972634d44002 /sc
parent36ce8cb4ed9d811a59159cfd4018d56cfa660ec9 (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.hxx3
-rw-r--r--sc/source/core/data/postit.cxx56
2 files changed, 31 insertions, 28 deletions
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index a6bfe232dd4b..129989b94fa5 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 f79a70e8256c..8c636693b3b3 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
{