[Libreoffice-commits] core.git: starmath/source

Takeshi Abe tabe at fixedpoint.jp
Fri Oct 7 04:12:58 UTC 2016


 starmath/source/parse.cxx |   32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

New commits:
commit 33c57f15501dbd05834cd8844e9124b06536e62c
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Oct 6 18:17:15 2016 +0900

    starmath: Simplify code with std::unique_ptr
    
    Change-Id: I2f6f993b92ae7f2f89b2d9d6c89b51d827226a3d
    Reviewed-on: https://gerrit.libreoffice.org/29554
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>
    Tested-by: Takeshi Abe <tabe at fixedpoint.jp>

diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 4977a82..56023ad 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1935,9 +1935,7 @@ void SmParser::DoBrace()
     assert(m_aCurToken.eType == TLEFT  ||  TokenInGroup(TG::LBrace));
 
     std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken));
-    SmNode *pBody   = nullptr,
-           *pLeft   = nullptr,
-           *pRight  = nullptr;
+    std::unique_ptr<SmNode> pBody, pLeft, pRight;
     SmScaleMode   eScaleMode = SCALE_NONE;
     SmParseError  eError     = PE_NONE;
 
@@ -1949,11 +1947,11 @@ void SmParser::DoBrace()
         // check for left bracket
         if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace))
         {
-            pLeft = new SmMathSymbolNode(m_aCurToken);
+            pLeft.reset(new SmMathSymbolNode(m_aCurToken));
 
             NextToken();
             DoBracebody(true);
-            pBody = popOrZero(m_aNodeStack);
+            pBody.reset(popOrZero(m_aNodeStack));
 
             if (m_aCurToken.eType == TRIGHT)
             {   NextToken();
@@ -1961,7 +1959,7 @@ void SmParser::DoBrace()
                 // check for right bracket
                 if (TokenInGroup(TG::LBrace) || TokenInGroup(TG::RBrace))
                 {
-                    pRight = new SmMathSymbolNode(m_aCurToken);
+                    pRight.reset(new SmMathSymbolNode(m_aCurToken));
                     NextToken();
                 }
                 else
@@ -1977,11 +1975,11 @@ void SmParser::DoBrace()
     {
         assert(TokenInGroup(TG::LBrace));
 
-        pLeft = new SmMathSymbolNode(m_aCurToken);
+        pLeft.reset(new SmMathSymbolNode(m_aCurToken));
 
         NextToken();
         DoBracebody(false);
-        pBody = popOrZero(m_aNodeStack);
+        pBody.reset(popOrZero(m_aNodeStack));
 
         SmTokenType  eExpectedType = TUNKNOWN;
         switch (pLeft->GetToken().eType)
@@ -2000,29 +1998,23 @@ void SmParser::DoBrace()
 
         if (m_aCurToken.eType == eExpectedType)
         {
-                pRight = new SmMathSymbolNode(m_aCurToken);
-                NextToken();
+            pRight.reset(new SmMathSymbolNode(m_aCurToken));
+            NextToken();
         }
         else
             eError = PE_PARENT_MISMATCH;
     }
 
     if (eError == PE_NONE)
-    {   OSL_ENSURE(pLeft,  "Sm: NULL pointer");
-        OSL_ENSURE(pRight, "Sm: NULL pointer");
-        pSNode->SetSubNodes(pLeft, pBody, pRight);
+    {
+        assert(pLeft);
+        assert(pRight);
+        pSNode->SetSubNodes(pLeft.release(), pBody.release(), pRight.release());
         pSNode->SetScaleMode(eScaleMode);
         m_aNodeStack.push_front(std::move(pSNode));
     }
     else
-    {
-        pSNode.reset();
-        delete pBody;
-        delete pLeft;
-        delete pRight;
-
         Error(eError);
-    }
 }
 
 void SmParser::DoBracebody(bool bIsLeftRight)


More information about the Libreoffice-commits mailing list