From d5b81ce5722398cc8c259d76e7cd1a5ddc2c562f Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 16 Dec 2016 14:45:46 -0800 Subject: Return unique_ptr<> from IPDF_StructTree Delete some dead code in the process. Review-Url: https://codereview.chromium.org/2585873002 --- core/fpdfdoc/doc_tagged.cpp | 47 ++++++++------------------------------------- core/fpdfdoc/fpdf_tagged.h | 8 +++++--- core/fpdfdoc/tagged_int.h | 1 - 3 files changed, 13 insertions(+), 43 deletions(-) (limited to 'core') diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp index 10c573b5ca..39feaeef88 100644 --- a/core/fpdfdoc/doc_tagged.cpp +++ b/core/fpdfdoc/doc_tagged.cpp @@ -5,6 +5,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include +#include +#include #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -16,6 +18,7 @@ #include "core/fpdfdoc/cpdf_numbertree.h" #include "core/fpdfdoc/fpdf_tagged.h" #include "core/fpdfdoc/tagged_int.h" +#include "third_party/base/ptr_util.h" namespace { @@ -30,24 +33,15 @@ bool IsTagged(const CPDF_Document* pDoc) { } // namespace // static -IPDF_StructTree* IPDF_StructTree::LoadPage(const CPDF_Document* pDoc, - const CPDF_Dictionary* pPageDict) { +std::unique_ptr IPDF_StructTree::LoadPage( + const CPDF_Document* pDoc, + const CPDF_Dictionary* pPageDict) { if (!IsTagged(pDoc)) return nullptr; - CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); + auto pTree = pdfium::MakeUnique(pDoc); pTree->LoadPageTree(pPageDict); - return pTree; -} - -// static. -IPDF_StructTree* IPDF_StructTree::LoadDoc(const CPDF_Document* pDoc) { - if (!IsTagged(pDoc)) - return nullptr; - - CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); - pTree->LoadDocTree(); - return pTree; + return std::move(pTree); } CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) @@ -65,31 +59,6 @@ IPDF_StructElement* CPDF_StructTreeImpl::GetTopElement(int i) const { return m_Kids[i].Get(); } -void CPDF_StructTreeImpl::LoadDocTree() { - m_pPage = nullptr; - if (!m_pTreeRoot) - return; - - CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectFor("K"); - if (!pKids) - return; - - if (CPDF_Dictionary* pDict = pKids->AsDictionary()) { - m_Kids.push_back(CFX_RetainPtr( - new CPDF_StructElementImpl(this, nullptr, pDict))); - return; - } - - CPDF_Array* pArray = pKids->AsArray(); - if (!pArray) - return; - - for (size_t i = 0; i < pArray->GetCount(); i++) { - m_Kids.push_back(CFX_RetainPtr( - new CPDF_StructElementImpl(this, nullptr, pArray->GetDictAt(i)))); - } -} - void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { m_pPage = pPageDict; if (!m_pTreeRoot) diff --git a/core/fpdfdoc/fpdf_tagged.h b/core/fpdfdoc/fpdf_tagged.h index 716e626743..aa697ca248 100644 --- a/core/fpdfdoc/fpdf_tagged.h +++ b/core/fpdfdoc/fpdf_tagged.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFDOC_FPDF_TAGGED_H_ #define CORE_FPDFDOC_FPDF_TAGGED_H_ +#include + #include "core/fxge/fx_dib.h" class CPDF_Dictionary; @@ -15,9 +17,9 @@ class IPDF_StructElement; class IPDF_StructTree { public: - static IPDF_StructTree* LoadDoc(const CPDF_Document* pDoc); - static IPDF_StructTree* LoadPage(const CPDF_Document* pDoc, - const CPDF_Dictionary* pPageDict); + static std::unique_ptr LoadPage( + const CPDF_Document* pDoc, + const CPDF_Dictionary* pPageDict); virtual ~IPDF_StructTree() {} diff --git a/core/fpdfdoc/tagged_int.h b/core/fpdfdoc/tagged_int.h index 43e43f1ed6..03f1c40ad6 100644 --- a/core/fpdfdoc/tagged_int.h +++ b/core/fpdfdoc/tagged_int.h @@ -26,7 +26,6 @@ class CPDF_StructTreeImpl final : public IPDF_StructTree { int CountTopElements() const override; IPDF_StructElement* GetTopElement(int i) const override; - void LoadDocTree(); void LoadPageTree(const CPDF_Dictionary* pPageDict); CPDF_StructElementImpl* AddPageNode( CPDF_Dictionary* pElement, -- cgit v1.2.3