diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2017-03-07 19:19:31 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2017-03-08 03:20:30 +0000 |
commit | c8df7f052450a7f6d87dae8dbdbd686bdb091939 (patch) | |
tree | f472d43369e3e2f2b2d4848901581497b4961f85 /starmath | |
parent | ca0d1f127d2f03661955fa2e55f507e6afdb6e13 (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/parse.hxx | 2 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 22 |
2 files changed, 10 insertions, 14 deletions
diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx index 76d602f1a3ed..6804b1a9ec02 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 76c4b243332a..329bd9fe4c44 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(); } |