starmath/inc/cursor.hxx    |    4 ++--
 starmath/source/cursor.cxx |   24 +++++++++++-------------
 2 files changed, 13 insertions(+), 15 deletions(-)

New commits:
commit 9fd7808f79fe48af9d9a4d47561abb9b8c66cbc3
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Aug 16 12:22:43 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Aug 18 09:38:28 2018 +0200

    loplugin:useuniqueptr pass SmNodeList around by std::unique_ptr(2)
    
    Change-Id: I53b7f39ddc150367bc5f9c4a7ee7049d59e9f485
    Reviewed-on: https://gerrit.libreoffice.org/59231
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 4c3e5b3eb0cd..b04b39748829 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -261,7 +261,7 @@ private:
     void BuildGraph();
 
     /** Insert new nodes in the tree after position */
-    void InsertNodes(SmNodeList* pNewNodes);
+    void InsertNodes(std::unique_ptr<SmNodeList> pNewNodes);
 
     /** tries to set position to a specific SmCaretPos
      *
@@ -273,7 +273,7 @@ private:
     void AnnotateSelection();
 
     /** Clone list of nodes in a clipboard (creates a deep clone) */
-    static SmNodeList* CloneList(SmClipboard &rClipboard);
+    static std::unique_ptr<SmNodeList> CloneList(SmClipboard &rClipboard);
 
     /** Find an iterator pointing to the node in pLineList following rCaretPos
      *
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 4afe12d2e445..cc0037f2ef85 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -291,9 +291,8 @@ void SmCursor::Delete(){
     FinishEdit(std::move(pLineList), pLineParent, nLineOffset, PosAfterDelete);
 }
 
-void SmCursor::InsertNodes(SmNodeList* pNewNodes){
+void SmCursor::InsertNodes(std::unique_ptr<SmNodeList> pNewNodes){
     if(pNewNodes->empty()){
-        delete pNewNodes;
         return;
     }
 
@@ -331,8 +330,7 @@ void SmCursor::InsertNodes(SmNodeList* pNewNodes){
                         PatchLineList(pLineList.get(), patchIt);
     SmCaretPos PosAfterInsert = PatchLineList(pLineList.get(), it);
     //Release list, we've taken the nodes
-    delete pNewNodes;
-    pNewNodes = nullptr;
+    pNewNodes.reset();
 
     //Finish editing
     FinishEdit(std::move(pLineList), pLineParent, nParentIndex, 
PosAfterInsert);
@@ -881,9 +879,9 @@ void SmCursor::InsertText(const OUString& aString)
     pText->AdjustFontDesc();
     pText->Prepare(mpDocShell->GetFormat(), *mpDocShell, 0);
 
-    SmNodeList* pList = new SmNodeList;
+    std::unique_ptr<SmNodeList> pList(new SmNodeList);
     pList->push_front(pText);
-    InsertNodes(pList);
+    InsertNodes(std::move(pList));
 
     EndEdit();
 }
@@ -983,9 +981,9 @@ void SmCursor::InsertElement(SmFormulaElement element){
     pNewNode->Prepare(mpDocShell->GetFormat(), *mpDocShell, 0);
 
     //Insert new node
-    SmNodeList* pList = new SmNodeList;
+    std::unique_ptr<SmNodeList> pList(new SmNodeList);
     pList->push_front(pNewNode);
-    InsertNodes(pList);
+    InsertNodes(std::move(pList));
 
     EndEdit();
 }
@@ -1010,9 +1008,9 @@ void SmCursor::InsertSpecial(const OUString& _aString)
     pSpecial->Prepare(mpDocShell->GetFormat(), *mpDocShell, 0);
 
     //Insert the node
-    SmNodeList* pList = new SmNodeList;
+    std::unique_ptr<SmNodeList> pList(new SmNodeList);
     pList->push_front(pSpecial);
-    InsertNodes(pList);
+    InsertNodes(std::move(pList));
 
     EndEdit();
 }
@@ -1035,7 +1033,7 @@ void SmCursor::InsertCommandText(const OUString& 
aCommandText) {
     Delete();
 
     //Insert it
-    InsertNodes(pLineList.release());
+    InsertNodes(std::move(pLineList));
 
     EndEdit();
 }
@@ -1087,9 +1085,9 @@ void SmCursor::Paste() {
     EndEdit();
 }
 
-SmNodeList* SmCursor::CloneList(SmClipboard &rClipboard){
+std::unique_ptr<SmNodeList> SmCursor::CloneList(SmClipboard &rClipboard){
     SmCloningVisitor aCloneFactory;
-    SmNodeList* pClones = new SmNodeList;
+    std::unique_ptr<SmNodeList> pClones(new SmNodeList);
 
     for(auto &xNode : rClipboard){
         SmNode *pClone = aCloneFactory.Clone(xNode.get());
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to