[Libreoffice-commits] core.git: sc/inc sc/source
Eike Rathke
erack at redhat.com
Tue Mar 7 22:57:04 UTC 2017
sc/inc/postit.hxx | 8 ++++++
sc/source/core/data/postit.cxx | 48 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
New commits:
commit 3c0fe2813bb0a1dfb30eba1af8aae24a3fea4f83
Author: Eike Rathke <erack at redhat.com>
Date: Tue Mar 7 21:26:56 2017 +0100
coverity#1401471 implement move assignment and move ctor at ScCaptionPtr
Change-Id: Ic429f5e177bb1a35857f00c6e13e5cbb34d46578
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index 2904d82..6e49727 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -45,9 +45,11 @@ public:
ScCaptionPtr();
explicit ScCaptionPtr( SdrCaptionObj* p );
ScCaptionPtr( const ScCaptionPtr& r );
+ ScCaptionPtr( ScCaptionPtr&& r );
~ScCaptionPtr();
ScCaptionPtr& operator=( const ScCaptionPtr& r );
+ ScCaptionPtr& operator=( ScCaptionPtr&& r );
explicit operator bool() const { return mpCaption != nullptr; }
SdrCaptionObj* get() const { return mpCaption; }
SdrCaptionObj* operator->() const { return mpCaption; }
@@ -96,6 +98,12 @@ private:
*/
void removeFromList();
+ /** Replace this instance with pNew in a list, if any.
+
+ Used by move-ctor and move assignment operator.
+ */
+ void replaceInList( ScCaptionPtr* pNew );
+
/** Dissolve list when the caption object is released or gone. */
void dissolve();
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 6c75228..b4ec948 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -476,6 +476,28 @@ ScCaptionPtr::ScCaptionPtr( const ScCaptionPtr& r ) :
}
}
+ScCaptionPtr::ScCaptionPtr( ScCaptionPtr&& r ) :
+ mpHead(r.mpHead), mpNext(r.mpNext), mpCaption(r.mpCaption)
+{
+ r.replaceInList( this );
+ r.mpCaption = nullptr;
+}
+
+ScCaptionPtr& ScCaptionPtr::operator=( ScCaptionPtr&& r )
+{
+ if (this == &r)
+ return *this;
+
+ mpHead = r.mpHead;
+ mpNext = r.mpNext;
+ mpCaption = r.mpCaption;
+
+ r.replaceInList( this );
+ r.mpCaption = nullptr;
+
+ return *this;
+}
+
ScCaptionPtr& ScCaptionPtr::operator=( const ScCaptionPtr& r )
{
if (this == &r)
@@ -521,6 +543,32 @@ void ScCaptionPtr::newHead()
mpHead->mnRefs = 1;
}
+void ScCaptionPtr::replaceInList( ScCaptionPtr* pNew )
+{
+ if (!mpHead && !mpNext)
+ return;
+
+ assert(mpHead);
+ assert(mpCaption == pNew->mpCaption);
+
+ ScCaptionPtr* pThat = mpHead->mpFirst;
+ while (pThat && pThat != this && pThat->mpNext != this)
+ {
+ pThat = pThat->mpNext;
+ }
+ if (pThat && pThat != this)
+ {
+ assert(pThat->mpNext == this);
+ pThat->mpNext = pNew;
+ }
+ pNew->mpNext = mpNext;
+ if (mpHead->mpFirst == this)
+ mpHead->mpFirst = pNew;
+
+ mpHead = nullptr;
+ mpNext = nullptr;
+}
+
void ScCaptionPtr::removeFromList()
{
if (!mpHead && !mpNext && !mpCaption)
More information about the Libreoffice-commits
mailing list