From 7cdc660683c233787f18fccf0b63882eec097050 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 28 Mar 2017 09:56:48 -0700 Subject: Remove CFX_ArrayTemplate from CXFA_Node. Remove some unused arrays from helper functions while we're at it. Change-Id: I7cf9efaeb269df8b9c32b128fc9595682102f0e1 Reviewed-on: https://pdfium-review.googlesource.com/3240 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- xfa/fxfa/parser/cxfa_node.cpp | 46 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 509decd037..a1074b9ef2 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -81,29 +81,20 @@ int32_t GetCount(CXFA_Node* pInstMgrNode) { return iCount; } -void SortNodeArrayByDocumentIdx(const std::unordered_set& rgNodeSet, - std::vector& rgNodeArray, - CFX_ArrayTemplate& rgIdxArray) { - int32_t iCount = pdfium::CollectionSize(rgNodeSet); - rgNodeArray.resize(iCount); - rgIdxArray.SetSize(iCount); - if (iCount == 0) - return; +std::vector NodesSortedByDocumentIdx( + const std::unordered_set& rgNodeSet) { + if (rgNodeSet.empty()) + return std::vector(); - int32_t iIndex = -1; - int32_t iTotalIndex = -1; + std::vector rgNodeArray; CXFA_Node* pCommonParent = (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); - pNode && iIndex < iCount; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - iTotalIndex++; - if (pdfium::ContainsValue(rgNodeSet, pNode)) { - iIndex++; - rgNodeArray[iIndex] = pNode; - rgIdxArray[iIndex] = iTotalIndex; - } + pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pdfium::ContainsValue(rgNodeSet, pNode)) + rgNodeArray.push_back(pNode); } + return rgNodeArray; } using CXFA_NodeSetPair = @@ -158,26 +149,21 @@ void ReorderDataNodes(const std::unordered_set& sSet1, if (!pNodeSetPair) continue; if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { - std::vector rgNodeArray1; - std::vector rgNodeArray2; - CFX_ArrayTemplate rgIdxArray1; - CFX_ArrayTemplate rgIdxArray2; - SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1, - rgIdxArray1); - SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2, - rgIdxArray2); + std::vector rgNodeArray1 = + NodesSortedByDocumentIdx(pNodeSetPair->first); + std::vector rgNodeArray2 = + NodesSortedByDocumentIdx(pNodeSetPair->second); CXFA_Node* pParentNode = nullptr; CXFA_Node* pBeforeNode = nullptr; if (bInsertBefore) { - pBeforeNode = rgNodeArray2[0]; + pBeforeNode = rgNodeArray2.front(); pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); } else { - CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1]; + CXFA_Node* pLastNode = rgNodeArray2.back(); pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); } - for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) { - CXFA_Node* pCurNode = rgNodeArray1[iIdx]; + for (auto* pCurNode : rgNodeArray1) { pParentNode->RemoveChild(pCurNode); pParentNode->InsertChild(pCurNode, pBeforeNode); } -- cgit v1.2.3