Clean up CPDF_BookmarkTree. - Change GetFirstChild() and GetNextSibling() to take a const-ref parameter. - Remove unused GetDocument(). - Change all variables to Chromium style. - Fix a nit by flipping the logic of a comparison. Change-Id: If4a69eea49b6fddb38ff1f4d6c5e2115b775d4bd Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79301 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp index 5c4fffe..175e925 100644 --- a/core/fpdfdoc/cpdf_bookmarktree.cpp +++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -9,29 +9,31 @@ #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" -CPDF_BookmarkTree::CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {} +CPDF_BookmarkTree::CPDF_BookmarkTree(CPDF_Document* doc) : document_(doc) {} CPDF_BookmarkTree::~CPDF_BookmarkTree() = default; -CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(CPDF_Bookmark* parent) const { - const CPDF_Dictionary* pParentDict = parent->GetDict(); - if (pParentDict) - return CPDF_Bookmark(pParentDict->GetDictFor("First")); +CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( + const CPDF_Bookmark& parent) const { + const CPDF_Dictionary* parent_dict = parent.GetDict(); + if (parent_dict) + return CPDF_Bookmark(parent_dict->GetDictFor("First")); - CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); - if (!pRoot) + const CPDF_Dictionary* root = document_->GetRoot(); + if (!root) return CPDF_Bookmark(); - CPDF_Dictionary* pOutlines = pRoot->GetDictFor("Outlines"); - return pOutlines ? CPDF_Bookmark(pOutlines->GetDictFor("First")) - : CPDF_Bookmark(); + const CPDF_Dictionary* outlines = root->GetDictFor("Outlines"); + return outlines ? CPDF_Bookmark(outlines->GetDictFor("First")) + : CPDF_Bookmark(); } -CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(CPDF_Bookmark* bookmark) const { - const CPDF_Dictionary* pDict = bookmark->GetDict(); - if (!pDict) +CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( + const CPDF_Bookmark& bookmark) const { + const CPDF_Dictionary* dict = bookmark.GetDict(); + if (!dict) return CPDF_Bookmark(); - const CPDF_Dictionary* pNext = pDict->GetDictFor("Next"); - return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext); + const CPDF_Dictionary* next = dict->GetDictFor("Next"); + return next != dict ? CPDF_Bookmark(next) : CPDF_Bookmark(); }
diff --git a/core/fpdfdoc/cpdf_bookmarktree.h b/core/fpdfdoc/cpdf_bookmarktree.h index b374bfa..6cadbb7 100644 --- a/core/fpdfdoc/cpdf_bookmarktree.h +++ b/core/fpdfdoc/cpdf_bookmarktree.h
@@ -14,15 +14,14 @@ class CPDF_BookmarkTree { public: - explicit CPDF_BookmarkTree(CPDF_Document* pDoc); + explicit CPDF_BookmarkTree(CPDF_Document* doc); ~CPDF_BookmarkTree(); - CPDF_Bookmark GetFirstChild(CPDF_Bookmark* parent) const; - CPDF_Bookmark GetNextSibling(CPDF_Bookmark* bookmark) const; - CPDF_Document* GetDocument() const { return m_pDocument.Get(); } + CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const; + CPDF_Bookmark GetNextSibling(const CPDF_Bookmark& bookmark) const; private: - UnownedPtr<CPDF_Document> const m_pDocument; + UnownedPtr<CPDF_Document> const document_; }; #endif // CORE_FPDFDOC_CPDF_BOOKMARKTREE_H_
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp index 83d9a4a..551918f 100644 --- a/fpdfsdk/fpdf_doc.cpp +++ b/fpdfsdk/fpdf_doc.cpp
@@ -48,13 +48,13 @@ } // Go into children items. - CPDF_Bookmark child = tree.GetFirstChild(&bookmark); + CPDF_Bookmark child = tree.GetFirstChild(bookmark); while (child.GetDict() && !pdfium::Contains(*visited, child.GetDict())) { // Check this item and its children. CPDF_Bookmark found = FindBookmark(tree, child, title, visited); if (found.GetDict()) return found; - child = tree.GetNextSibling(&child); + child = tree.GetNextSibling(child); } return CPDF_Bookmark(); } @@ -81,7 +81,7 @@ CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); return FPDFBookmarkFromCPDFDictionary( - tree.GetFirstChild(&cBookmark).GetDict()); + tree.GetFirstChild(cBookmark).GetDict()); } FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV @@ -96,7 +96,7 @@ CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark cBookmark(CPDFDictionaryFromFPDFBookmark(bookmark)); return FPDFBookmarkFromCPDFDictionary( - tree.GetNextSibling(&cBookmark).GetDict()); + tree.GetNextSibling(cBookmark).GetDict()); } FPDF_EXPORT unsigned long FPDF_CALLCONV