Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(844)

Unified Diff: core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp

Issue 1904303002: Remove next batch of CFX_ arrays from fpdf_edit_doc.cpp (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use ScopedSetInsertion to be totally cool. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
index 61bbf67853ffe50e91f0f339b0a40eaedfd4355a..ceca67ceef8cc1b00fa29f50b56afa26701dd91b 100644
--- a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
+++ b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
@@ -6,6 +6,7 @@
#include <limits.h>
+#include <set>
#include <vector>
#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<CPDF_Dictionary*>& stackList) {
+ std::set<CPDF_Dictionary*>* 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<CPDF_Dictionary*>(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<CPDF_Dictionary*> stack;
- stack.Add(pPages);
- if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, stack) < 0) {
+ std::set<CPDF_Dictionary*> 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<CPDF_Dictionary*> stack;
- stack.Add(pPages);
- if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) {
+
+ std::set<CPDF_Dictionary*> stack = {pPages};
+ if (InsertDeletePDFPage(this, pPages, iPage, nullptr, FALSE, &stack) < 0)
return;
- }
+
m_PageList.RemoveAt(iPage);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698