[Libreoffice-commits] core.git: starmath/inc starmath/source
Takeshi Abe
tabe at fixedpoint.jp
Thu Mar 23 04:21:23 UTC 2017
starmath/inc/parse.hxx | 6 ++---
starmath/source/parse.cxx | 53 ++++++++++++++++------------------------------
2 files changed, 22 insertions(+), 37 deletions(-)
New commits:
commit faeda4e29e0be16050dd919a62ecf69a4ffdf2f8
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Thu Mar 23 12:10:46 2017 +0900
starmath: Make DoProduct()/DoSum()/DoRelation() return SmNode
to reduce an excessive number of stack operations.
Change-Id: Ia4ef08dce76d318c56bf7d112f686e13d1b2660e
Reviewed-on: https://gerrit.libreoffice.org/35551
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 d158c3995151..8872b8edac9a 100644
--- a/starmath/inc/parse.hxx
+++ b/starmath/inc/parse.hxx
@@ -64,9 +64,9 @@ class SmParser
SmTableNode *DoTable();
void DoLine();
SmNode *DoExpression();
- void DoRelation();
- void DoSum();
- void DoProduct();
+ SmNode *DoRelation();
+ SmNode *DoSum();
+ SmNode *DoProduct();
SmNode *DoSubSup(TG nActiveGroup, SmNode *pGivenNode);
SmNode *DoOpSubSup();
SmNode *DoPower();
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 14ab62aad504..07383f3e359e 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1037,15 +1037,9 @@ SmNode *SmParser::DoExpression()
}
SmNodeArray RelationArray;
-
- DoRelation();
- RelationArray.push_back(popOrZero(m_aNodeStack));
-
+ RelationArray.push_back(DoRelation());
while (m_aCurToken.nLevel >= 4)
- {
- DoRelation();
- RelationArray.push_back(popOrZero(m_aNodeStack));
- }
+ RelationArray.push_back(DoRelation());
if (RelationArray.size() > 1)
{
@@ -1061,41 +1055,35 @@ SmNode *SmParser::DoExpression()
}
}
-void SmParser::DoRelation()
+SmNode *SmParser::DoRelation()
{
- DoSum();
+ SmNode *pFirst = DoSum();
while (TokenInGroup(TG::Relation))
{
std::unique_ptr<SmStructureNode> pSNode(new SmBinHorNode(m_aCurToken));
- SmNode *pFirst = popOrZero(m_aNodeStack);
-
SmNode *pSecond = DoOpSubSup();
-
- DoSum();
-
- pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack));
- m_aNodeStack.push_front(std::move(pSNode));
+ SmNode *pThird = DoSum();
+ pSNode->SetSubNodes(pFirst, pSecond, pThird);
+ pFirst = pSNode.release();
}
+ return pFirst;
}
-void SmParser::DoSum()
+SmNode *SmParser::DoSum()
{
- DoProduct();
+ SmNode *pFirst = DoProduct();
while (TokenInGroup(TG::Sum))
{
std::unique_ptr<SmStructureNode> pSNode(new SmBinHorNode(m_aCurToken));
- SmNode *pFirst = popOrZero(m_aNodeStack);
-
SmNode *pSecond = DoOpSubSup();
-
- DoProduct();
-
- pSNode->SetSubNodes(pFirst, pSecond, popOrZero(m_aNodeStack));
- m_aNodeStack.push_front(std::move(pSNode));
+ SmNode *pThird = DoProduct();
+ pSNode->SetSubNodes(pFirst, pSecond, pThird);
+ pFirst = pSNode.release();
}
+ return pFirst;
}
-void SmParser::DoProduct()
+SmNode *SmParser::DoProduct()
{
SmNode *pFirst = DoPower();
@@ -1165,7 +1153,7 @@ void SmParser::DoProduct()
}
pFirst = pSNode;
}
- m_aNodeStack.emplace_front(pFirst);
+ return pFirst;
}
SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
@@ -1197,7 +1185,7 @@ SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
if (eType == TFROM || eType == TTO)
{
// parse limits in old 4.0 and 5.0 style
- DoRelation();
+ m_aNodeStack.emplace_front(DoRelation());
}
else
m_aNodeStack.emplace_front(DoTerm(true));
@@ -2072,11 +2060,8 @@ SmTableNode *SmParser::DoBinom()
NextToken();
- DoSum();
- DoSum();
-
- SmNode *pSecond = popOrZero(m_aNodeStack);
- SmNode *pFirst = popOrZero(m_aNodeStack);
+ SmNode *pFirst = DoSum();
+ SmNode *pSecond = DoSum();
pSNode->SetSubNodes(pFirst, pSecond);
return pSNode.release();
}
More information about the Libreoffice-commits
mailing list