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

Takeshi Abe tabe at fixedpoint.jp
Mon Feb 5 23:30:46 UTC 2018


 starmath/inc/parse.hxx    |    2 +-
 starmath/source/parse.cxx |   22 +++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)

New commits:
commit 715114595e0feec49c4d54cc5eb26f13dccb7968
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Mon Feb 5 18:01:21 2018 +0900

    starmath: Make DoAlign() return std::unique_ptr
    
    to take advantage of copy elision and simplify client code.
    
    Change-Id: I9e08bc2b9743563f483657c7348abca05dd34c85
    Reviewed-on: https://gerrit.libreoffice.org/49222
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>

diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx
index a2faa73a3b40..e3ec707d8bf4 100644
--- a/starmath/inc/parse.hxx
+++ b/starmath/inc/parse.hxx
@@ -93,7 +93,7 @@ class SmParser
     SmOperNode *DoOperator();
     SmNode *DoOper();
     SmStructureNode *DoUnOper();
-    SmNode *DoAlign(bool bUseExtraSpaces = true);
+    std::unique_ptr<SmNode> DoAlign(bool bUseExtraSpaces = true);
     SmStructureNode *DoFontAttribut();
     SmAttributNode *DoAttribut();
     SmStructureNode *DoFont();
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 7e026673a69a..e097e87e1b8e 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -969,7 +969,7 @@ std::unique_ptr<SmTableNode> SmParser::DoTable()
     return xSNode;
 }
 
-SmNode *SmParser::DoAlign(bool bUseExtraSpaces)
+std::unique_ptr<SmNode> SmParser::DoAlign(bool bUseExtraSpaces)
     // parse alignment info (if any), then go on with rest of expression
 {
     DepthProtect aDepthGuard(m_nParseDepth);
@@ -986,7 +986,7 @@ SmNode *SmParser::DoAlign(bool bUseExtraSpaces)
 
         // allow for just one align statement in 5.0
         if (TokenInGroup(TG::Align))
-            return DoError(SmParseError::DoubleAlign);
+            return std::unique_ptr<SmNode>(DoError(SmParseError::DoubleAlign));
     }
 
     auto pNode = DoExpression(bUseExtraSpaces);
@@ -994,9 +994,9 @@ SmNode *SmParser::DoAlign(bool bUseExtraSpaces)
     if (xSNode)
     {
         xSNode->SetSubNode(0, pNode.release());
-        return xSNode.release();
+        return std::move(xSNode); // this explicit move can be omitted since C++14
     }
-    return pNode.release();
+    return pNode;
 }
 
 // Postcondition: m_aCurToken.eType == TEND || m_aCurToken.eType == TNEWLINE
@@ -1012,7 +1012,7 @@ SmLineNode *SmParser::DoLine()
     // (and go on with expressions that must not have alignment
     // statements in 'while' loop below. See also 'Expression()'.)
     if (m_aCurToken.eType != TEND  &&  m_aCurToken.eType != TNEWLINE)
-        ExpressionArray.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
+        ExpressionArray.push_back(DoAlign());
 
     while (m_aCurToken.eType != TEND  &&  m_aCurToken.eType != TNEWLINE)
         ExpressionArray.push_back(DoExpression());
@@ -1336,7 +1336,7 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent)
                 return xSNode.release();
             }
 
-            std::unique_ptr<SmNode> pNode(DoAlign(!bNoSpace));
+            auto pNode = DoAlign(!bNoSpace);
             if (m_aCurToken.eType == TRGROUP) {
                 NextToken();
                 return pNode.release();
@@ -2051,7 +2051,7 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight)
             }
             else if (m_aCurToken.eType != TRIGHT)
             {
-                aNodes.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
+                aNodes.push_back(DoAlign());
                 if (m_aCurToken.eType != TMLINE  &&  m_aCurToken.eType != TRIGHT)
                     aNodes.emplace_back(std::unique_ptr<SmNode>(DoError(SmParseError::RightExpected)));
             }
@@ -2068,7 +2068,7 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight)
             }
             else if (!TokenInGroup(TG::RBrace))
             {
-                aNodes.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
+                aNodes.push_back(DoAlign());
                 if (m_aCurToken.eType != TMLINE  &&  !TokenInGroup(TG::RBrace))
                     aNodes.emplace_back(std::unique_ptr<SmNode>(DoError(SmParseError::RbraceExpected)));
             }
@@ -2153,7 +2153,7 @@ SmStructureNode *SmParser::DoStack()
     do
     {
         NextToken();
-        aExprArr.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
+        aExprArr.push_back(DoAlign());
     }
     while (m_aCurToken.eType == TPOUND);
 
@@ -2181,7 +2181,7 @@ SmStructureNode *SmParser::DoMatrix()
     do
     {
         NextToken();
-        aExprArr.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
+        aExprArr.push_back(DoAlign());
     }
     while (m_aCurToken.eType == TPOUND);
 
@@ -2192,7 +2192,7 @@ SmStructureNode *SmParser::DoMatrix()
         NextToken();
         for (size_t i = 0; i < nCol; i++)
         {
-            std::unique_ptr<SmNode> xNode(DoAlign());
+            auto xNode = DoAlign();
             if (i < (nCol - 1))
             {
                 if (m_aCurToken.eType == TPOUND)


More information about the Libreoffice-commits mailing list