summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2018-02-14 22:08:37 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2018-02-15 11:13:52 +0100
commitabcd7825101afb9ef9ff93932f8e1bd7c3bb91bb (patch)
treefabc5ff05ba53261c71ee7ab68ff79f3a935dae8 /starmath
parent1c8efde4daea648204e3ba19f8edc01ef3e548bd (diff)
starmath: Prefer moving subnodes to copying them
Change-Id: Id92dd0715daf43a63d09529f01a6583c23de7c7d Reviewed-on: https://gerrit.libreoffice.org/49725 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/node.hxx3
-rw-r--r--starmath/source/cursor.cxx7
-rw-r--r--starmath/source/mathmlimport.cxx20
-rw-r--r--starmath/source/node.cxx9
-rw-r--r--starmath/source/visitors.cxx2
5 files changed, 23 insertions, 18 deletions
diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index 01423959652b..f4d90b9ada05 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -235,8 +235,9 @@ public:
using SmNode::GetSubNode;
virtual SmNode * GetSubNode(size_t nIndex) override;
+ void ClearSubNodes();
void SetSubNodes(SmNode *pFirst, SmNode *pSecond, SmNode *pThird = nullptr);
- void SetSubNodes(const SmNodeArray &rNodeArray);
+ void SetSubNodes(SmNodeArray&& rNodeArray);
virtual void GetAccessibleText( OUStringBuffer &rText ) const override;
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index bc6d5227d043..1d0e987e02cc 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -219,7 +219,7 @@ void SmCursor::DeletePrev(OutputDevice* pDev){
else if(i > nLineOffset)
lines[i-1] = pLineParent->GetSubNode(i);
}
- pLineParent->SetSubNodes(lines);
+ pLineParent->SetSubNodes(std::move(lines));
//Rebuild graph
mpAnchor = nullptr;
mpPosition = nullptr;
@@ -1147,8 +1147,7 @@ SmNodeList* SmCursor::LineToList(SmStructureNode* pLine, SmNodeList* list){
list->push_back(pChild);
}
}
- SmNodeArray emptyArray(0);
- pLine->SetSubNodes(emptyArray);
+ pLine->ClearSubNodes();
delete pLine;
return list;
}
@@ -1436,7 +1435,7 @@ SmNode* SmNodeListParser::Expression(){
//Create SmExpressionNode, I hope SmToken() will do :)
SmStructureNode* pExpr = new SmExpressionNode(SmToken());
- pExpr->SetSubNodes(NodeArray);
+ pExpr->SetSubNodes(std::move(NodeArray));
return pExpr;
}
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 85361823fbf2..bf90545a5e99 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -1168,7 +1168,7 @@ void SmXMLFencedContext_Impl::EndElement()
SmToken aDummy;
SmStructureNode *pBody = new SmExpressionNode(aDummy);
- pBody->SetSubNodes(aRelationArray);
+ pBody->SetSubNodes(std::move(aRelationArray));
pSNode->SetSubNodes(pLeft,pBody,pRight);
@@ -1613,7 +1613,7 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup
aSubNodes[eSubSup+1] = popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack);
- pNode->SetSubNodes(aSubNodes);
+ pNode->SetSubNodes(std::move(aSubNodes));
rNodeStack.push_front(std::move(pNode));
}
@@ -1672,7 +1672,7 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
aSubNodes[aSup+1] = popOrZero(rNodeStack);
aSubNodes[aSub+1] = popOrZero(rNodeStack);
aSubNodes[0] = popOrZero(rNodeStack);
- pNode->SetSubNodes(aSubNodes);
+ pNode->SetSubNodes(std::move(aSubNodes));
rNodeStack.push_front(std::move(pNode));
}
@@ -2318,7 +2318,7 @@ void SmXMLDocContext_Impl::EndElement()
LineArray[n - (j + 1)] = pNode.release();
}
std::unique_ptr<SmStructureNode> pSNode2(new SmTableNode(aDummy));
- pSNode2->SetSubNodes(LineArray);
+ pSNode2->SetSubNodes(std::move(LineArray));
rNodeStack.push_front(std::move(pSNode2));
}
@@ -2454,7 +2454,7 @@ void SmXMLRowContext_Impl::EndElement()
SmToken aDummy;
std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(aToken));
SmStructureNode *pBody = new SmExpressionNode(aDummy);
- pBody->SetSubNodes(aRelationArray2);
+ pBody->SetSubNodes(std::move(aRelationArray2));
pSNode->SetSubNodes(pLeft,pBody,pRight);
pSNode->SetScaleMode(SmScaleMode::Height);
@@ -2489,7 +2489,7 @@ void SmXMLRowContext_Impl::EndElement()
SmToken aDummy;
std::unique_ptr<SmStructureNode> pSNode(new SmExpressionNode(aDummy));
- pSNode->SetSubNodes(aRelationArray);
+ pSNode->SetSubNodes(std::move(aRelationArray));
rNodeStack.push_front(std::move(pSNode));
}
@@ -2635,7 +2635,7 @@ void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
(!pScriptNode->GetToken().aText.isEmpty())))
aSubNodes[eSup+1] = pScriptNode;
- pNode->SetSubNodes(aSubNodes);
+ pNode->SetSubNodes(std::move(aSubNodes));
aReverseStack.push_front(std::move(pNode));
}
assert(!aReverseStack.empty());
@@ -2683,7 +2683,7 @@ void SmXMLTableContext_Impl::EndElement()
aRelationArray[0] = pArray;
SmToken aDummy;
SmExpressionNode* pExprNode = new SmExpressionNode(aDummy);
- pExprNode->SetSubNodes(aRelationArray);
+ pExprNode->SetSubNodes(std::move(aRelationArray));
pArray = pExprNode;
}
@@ -2701,7 +2701,7 @@ void SmXMLTableContext_Impl::EndElement()
std::unique_ptr<SmStructureNode> xArray(static_cast<SmStructureNode*>(elem.release()));
for (size_t i = 0; i < xArray->GetNumSubNodes(); ++i)
aExpressionArray[j++] = xArray->GetSubNode(i);
- xArray->SetSubNodes(SmNodeArray());
+ xArray->ClearSubNodes();
}
aReverseStack.clear();
@@ -2709,7 +2709,7 @@ void SmXMLTableContext_Impl::EndElement()
aToken.cMathChar = '\0';
aToken.eType = TMATRIX;
std::unique_ptr<SmMatrixNode> pSNode(new SmMatrixNode(aToken));
- pSNode->SetSubNodes(aExpressionArray);
+ pSNode->SetSubNodes(std::move(aExpressionArray));
pSNode->SetRowCol(nRows, nCols);
rNodeStack.push_front(std::move(pSNode));
}
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index d44845411267..6da2dd4bb0b9 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -378,6 +378,11 @@ SmStructureNode::~SmStructureNode()
}
+void SmStructureNode::ClearSubNodes()
+{
+ maSubNodes.clear();
+}
+
void SmStructureNode::SetSubNodes(SmNode *pFirst, SmNode *pSecond, SmNode *pThird)
{
size_t nSize = pThird ? 3 : (pSecond ? 2 : (pFirst ? 1 : 0));
@@ -392,9 +397,9 @@ void SmStructureNode::SetSubNodes(SmNode *pFirst, SmNode *pSecond, SmNode *pThir
ClaimPaternity();
}
-void SmStructureNode::SetSubNodes(const SmNodeArray &rNodeArray)
+void SmStructureNode::SetSubNodes(SmNodeArray&& rNodeArray)
{
- maSubNodes = rNodeArray;
+ maSubNodes = std::move(rNodeArray);
ClaimPaternity();
}
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 6bbc5d989013..6e19801f211c 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -1630,7 +1630,7 @@ void SmCloningVisitor::CloneKids( SmStructureNode* pSource, SmStructureNode* pTa
}
//Set subnodes of pTarget
- pTarget->SetSubNodes( aNodes );
+ pTarget->SetSubNodes( std::move(aNodes) );
//Restore result as where prior to call
mpResult = pCurrResult;