From 416cbeab1d93b1261dfb4584e0c8e47d9cd4720f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 10 Jul 2018 18:13:45 +0000 Subject: Make CPDF_StreamContentParser::m_pResources a const pointer. Move the code to select what it points at to a separate function, so the CPDF_StreamContentParser constructor only sets it once. Change-Id: I60013e77c8f37246282f94227a4aeb17270ee23c Reviewed-on: https://pdfium-review.googlesource.com/37450 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 15 ++++++++++----- core/fpdfapi/page/cpdf_streamcontentparser.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 640b7f7109..ba7388cf15 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -236,6 +236,14 @@ void ReplaceAbbr(CPDF_Object* pObj) { } } +CPDF_Dictionary* ChooseResourcesDict(CPDF_Dictionary* pResources, + CPDF_Dictionary* pParentResources, + CPDF_Dictionary* pPageResources) { + if (pResources) + return pResources; + return pParentResources ? pParentResources : pPageResources; +} + } // namespace CPDF_StreamContentParser::CPDF_StreamContentParser( @@ -251,7 +259,8 @@ CPDF_StreamContentParser::CPDF_StreamContentParser( : m_pDocument(pDocument), m_pPageResources(pPageResources), m_pParentResources(pParentResources), - m_pResources(pResources), + m_pResources( + ChooseResourcesDict(pResources, pParentResources, pPageResources)), m_pObjectHolder(pObjHolder), m_ParsedSet(parsedSet), m_BBox(rcBBox), @@ -268,10 +277,6 @@ CPDF_StreamContentParser::CPDF_StreamContentParser( m_bResourceMissing(false) { if (pmtContentToUser) m_mtContentToUser = *pmtContentToUser; - if (!m_pResources) - m_pResources = m_pParentResources; - if (!m_pResources) - m_pResources = m_pPageResources; if (pStates) { m_pCurStates->Copy(*pStates); } else { diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h index 238999b846..aac66e883b 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.h +++ b/core/fpdfapi/page/cpdf_streamcontentparser.h @@ -211,7 +211,7 @@ class CPDF_StreamContentParser { UnownedPtr const m_pDocument; UnownedPtr const m_pPageResources; UnownedPtr const m_pParentResources; - UnownedPtr m_pResources; + UnownedPtr const m_pResources; UnownedPtr const m_pObjectHolder; UnownedPtr> const m_ParsedSet; CFX_Matrix m_mtContentToUser; -- cgit v1.2.3