From df3d229b592d1ebc7019797e0015dd2219fa3d0c Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Tue, 3 Oct 2017 21:54:20 +0300 Subject: Simplify CPDF_Parser::GetIDArray Change-Id: Idbd205edcf7400ffc46edf4d9f09be6ace6d0e7f Reviewed-on: https://pdfium-review.googlesource.com/13734 Commit-Queue: Art Snake Reviewed-by: dsinclair --- core/fpdfapi/edit/cpdf_creator.cpp | 2 +- core/fpdfapi/parser/cpdf_parser.cpp | 19 ++----------------- core/fpdfapi/parser/cpdf_parser.h | 2 +- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index eecf37b981..9064854779 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -770,7 +770,7 @@ bool CPDF_Creator::Create(uint32_t flags) { } void CPDF_Creator::InitID() { - CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; + const CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; bool idArrayPreExisting = !!m_pIDArray; if (!idArrayPreExisting) { diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 02cba64541..c443c8baf2 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -1140,23 +1140,8 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { return true; } -CPDF_Array* CPDF_Parser::GetIDArray() { - if (!GetTrailer()) - return nullptr; - - CPDF_Object* pID = GetTrailer()->GetObjectFor("ID"); - if (!pID) - return nullptr; - - CPDF_Reference* pRef = pID->AsReference(); - if (!pRef) - return ToArray(pID); - - std::unique_ptr pNewObj = - ParseIndirectObject(nullptr, pRef->GetRefObjNum()); - pID = pNewObj.get(); - GetTrailer()->SetFor("ID", std::move(pNewObj)); - return ToArray(pID); +const CPDF_Array* CPDF_Parser::GetIDArray() const { + return GetTrailer() ? GetTrailer()->GetArrayFor("ID") : nullptr; } uint32_t CPDF_Parser::GetRootObjNum() { diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h index 2dee1ab9e1..7c6a75d8c5 100644 --- a/core/fpdfapi/parser/cpdf_parser.h +++ b/core/fpdfapi/parser/cpdf_parser.h @@ -63,7 +63,7 @@ class CPDF_Parser { uint32_t GetPermissions() const; uint32_t GetRootObjNum(); uint32_t GetInfoObjNum(); - CPDF_Array* GetIDArray(); + const CPDF_Array* GetIDArray() const; CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict.Get(); } -- cgit v1.2.3