From b88b8dc91ff8987f327c2c5180cacdad1d4464d4 Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 21 Apr 2016 17:41:05 -0700 Subject: Remove next batch of CFX_ arrays from fpdf_edit_doc.cpp Review URL: https://codereview.chromium.org/1904303002 --- core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp | 45 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp index 61bbf67853..ceca67ceef 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp @@ -6,6 +6,7 @@ #include +#include #include #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" @@ -1008,11 +1009,11 @@ static int InsertDeletePDFPage(CPDF_Document* pDoc, int nPagesToGo, CPDF_Dictionary* pPage, FX_BOOL bInsert, - CFX_ArrayTemplate& stackList) { + std::set* pVisited) { CPDF_Array* pKidList = pPages->GetArrayBy("Kids"); - if (!pKidList) { + if (!pKidList) return -1; - } + for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (pKid->GetStringBy("Type") == "Page") { @@ -1031,18 +1032,13 @@ static int InsertDeletePDFPage(CPDF_Document* pDoc, } else { int nPages = pKid->GetIntegerBy("Count"); if (nPagesToGo < nPages) { - int stackCount = stackList.GetSize(); - for (int j = 0; j < stackCount; ++j) { - if (pKid == stackList[j]) { - return -1; - } - } - stackList.Add(pKid); + if (pdfium::ContainsValue(*pVisited, pKid)) + return -1; + pdfium::ScopedSetInsertion(pVisited, pKid); if (InsertDeletePDFPage(pDoc, pKid, nPagesToGo, pPage, bInsert, - stackList) < 0) { + pVisited) < 0) { return -1; } - stackList.RemoveAt(stackCount); pPages->SetAtInteger( "Count", pPages->GetIntegerBy("Count") + (bInsert ? 1 : -1)); return 1; @@ -1078,11 +1074,9 @@ static int InsertNewPage(CPDF_Document* pDoc, pPages->SetAtInteger("Count", nPages + 1); pPageDict->SetAtReference("Parent", pDoc, pPages->GetObjNum()); } else { - CFX_ArrayTemplate stack; - stack.Add(pPages); - if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, stack) < 0) { + std::set stack = {pPages}; + if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, &stack) < 0) return -1; - } } pageList.InsertAt(iPage, pPageDict->GetObjNum()); return iPage; @@ -1108,22 +1102,21 @@ CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, void CPDF_Document::DeletePage(int iPage) { CPDF_Dictionary* pRoot = GetRoot(); - if (!pRoot) { + if (!pRoot) return; - } + CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); - if (!pPages) { + if (!pPages) return; - } + int nPages = pPages->GetIntegerBy("Count"); - if (iPage < 0 || iPage >= nPages) { + if (iPage < 0 || iPage >= nPages) return; - } - CFX_ArrayTemplate stack; - stack.Add(pPages); - if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) { + + std::set stack = {pPages}; + if (InsertDeletePDFPage(this, pPages, iPage, nullptr, FALSE, &stack) < 0) return; - } + m_PageList.RemoveAt(iPage); } -- cgit v1.2.3