starmath/inc/parse.hxx | 2 +- starmath/source/parse.cxx | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-)
New commits: commit c8df7f052450a7f6d87dae8dbdbd686bdb091939 Author: Takeshi Abe <t...@fixedpoint.jp> Date: Tue Mar 7 19:19:31 2017 +0900 starmath: Return the expression node from DoExpression() instead of pushing it to the stack. This saves extra pops. Change-Id: I2fcf9b86eab9ade45db4351b34bafbcbc42ef056 Reviewed-on: https://gerrit.libreoffice.org/34944 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Takeshi Abe <t...@fixedpoint.jp> diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx index 76d602f..6804b1a 100644 --- a/starmath/inc/parse.hxx +++ b/starmath/inc/parse.hxx @@ -63,7 +63,7 @@ class SmParser // grammar SmTableNode *DoTable(); void DoLine(); - void DoExpression(); + SmNode *DoExpression(); void DoRelation(); void DoSum(); void DoProduct(); diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index 76c4b24..329bd9f 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -982,13 +982,15 @@ void SmParser::DoAlign() } } - DoExpression(); + std::unique_ptr<SmNode> pNode(DoExpression()); if (pSNode) { - pSNode->SetSubNode(0, popOrZero(m_aNodeStack)); + pSNode->SetSubNode(0, pNode.release()); m_aNodeStack.push_front(std::move(pSNode)); } + else + m_aNodeStack.push_front(std::move(pNode)); } void SmParser::DoLine() @@ -1005,10 +1007,7 @@ void SmParser::DoLine() } while (m_aCurToken.eType != TEND && m_aCurToken.eType != TNEWLINE) - { - DoExpression(); - ExpressionArray.push_back(popOrZero(m_aNodeStack)); - } + ExpressionArray.push_back(DoExpression()); //If there's no expression, add an empty one. //this is to avoid a formula tree without any caret @@ -1025,7 +1024,7 @@ void SmParser::DoLine() m_aNodeStack.push_front(std::move(pSNode)); } -void SmParser::DoExpression() +SmNode *SmParser::DoExpression() { bool bUseExtraSpaces = true; if (!m_aNodeStack.empty()) @@ -1053,12 +1052,12 @@ void SmParser::DoExpression() std::unique_ptr<SmExpressionNode> pSNode(new SmExpressionNode(m_aCurToken)); pSNode->SetSubNodes(RelationArray); pSNode->SetUseExtraSpaces(bUseExtraSpaces); - m_aNodeStack.push_front(std::move(pSNode)); + return pSNode.release(); } else { // This expression has only one node so just push this node. - m_aNodeStack.push_front(std::unique_ptr<SmNode>(RelationArray[0])); + return RelationArray[0]; } } @@ -2326,10 +2325,7 @@ SmNode *SmParser::ParseExpression(const OUString &rBuffer) m_aNodeStack.clear(); NextToken(); - DoExpression(); - - SmNode* result = popOrZero(m_aNodeStack); - return result; + return DoExpression(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits