From e0ad6a4af5d9c5f5671a9ecd0aa437dedae52b16 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 15 Apr 2016 14:32:49 -0700 Subject: Avoid narrowing to StringC in CPDF_Name and CPDF_NameTree Remove redundant CPDF_Name constructors given promotion rules. Rework one char* in CPDF_PageContentGenerator. Review URL: https://codereview.chromium.org/1890973006 --- core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp | 8 ++++---- .../fpdf_edit/include/cpdf_pagecontentgenerator.h | 2 +- core/fpdfapi/fpdf_parser/cpdf_name.cpp | 4 ---- core/fpdfapi/fpdf_parser/include/cpdf_name.h | 2 -- core/fpdfdoc/doc_basic.cpp | 19 +++++++++++++------ core/fpdfdoc/include/fpdf_doc.h | 5 ++--- 6 files changed, 20 insertions(+), 20 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp index 20fd1959f2..08bdb5bb07 100644 --- a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp @@ -58,22 +58,22 @@ void CPDF_PageContentGenerator::GenerateContent() { } CFX_ByteString CPDF_PageContentGenerator::RealizeResource( CPDF_Object* pResourceObj, - const FX_CHAR* szType) { + const CFX_ByteString& bsType) { if (!m_pPage->m_pResources) { m_pPage->m_pResources = new CPDF_Dictionary; int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); m_pPage->m_pFormDict->SetAtReference("Resources", m_pDocument, objnum); } - CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictBy(szType); + CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictBy(bsType); if (!pResList) { pResList = new CPDF_Dictionary; - m_pPage->m_pResources->SetAt(szType, pResList); + m_pPage->m_pResources->SetAt(bsType, pResList); } m_pDocument->AddIndirectObject(pResourceObj); CFX_ByteString name; int idnum = 1; while (1) { - name.Format("FX%c%d", szType[0], idnum); + name.Format("FX%c%d", bsType[0], idnum); if (!pResList->KeyExist(name)) { break; } diff --git a/core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h b/core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h index 564a9ff54c..f60b083be1 100644 --- a/core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h +++ b/core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h @@ -32,7 +32,7 @@ class CPDF_PageContentGenerator { uint32_t size, CFX_Matrix& matrix); CFX_ByteString RealizeResource(CPDF_Object* pResourceObj, - const FX_CHAR* szType); + const CFX_ByteString& bsType); CPDF_Page* m_pPage; CPDF_Document* m_pDocument; diff --git a/core/fpdfapi/fpdf_parser/cpdf_name.cpp b/core/fpdfapi/fpdf_parser/cpdf_name.cpp index 2999772aec..7d67b51d7c 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_name.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_name.cpp @@ -10,10 +10,6 @@ CPDF_Name::CPDF_Name(const CFX_ByteString& str) : m_Name(str) {} -CPDF_Name::CPDF_Name(const CFX_ByteStringC& str) : m_Name(str) {} - -CPDF_Name::CPDF_Name(const FX_CHAR* str) : m_Name(str) {} - CPDF_Name::~CPDF_Name() {} CPDF_Object::Type CPDF_Name::GetType() const { diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_name.h b/core/fpdfapi/fpdf_parser/include/cpdf_name.h index bebccb5841..523238c892 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_name.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_name.h @@ -12,8 +12,6 @@ class CPDF_Name : public CPDF_Object { public: explicit CPDF_Name(const CFX_ByteString& str); - explicit CPDF_Name(const CFX_ByteStringC& str); - explicit CPDF_Name(const FX_CHAR* str); // CPDF_Object. Type GetType() const override; diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp index a3e94cb033..a0c6b2babc 100644 --- a/core/fpdfdoc/doc_basic.cpp +++ b/core/fpdfdoc/doc_basic.cpp @@ -71,12 +71,19 @@ FX_FLOAT CPDF_Dest::GetParam(int index) { CFX_ByteString CPDF_Dest::GetRemoteName() { return m_pObj ? m_pObj->GetString() : CFX_ByteString(); } + CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, - const CFX_ByteStringC& category) { - if (pDoc->GetRoot() && pDoc->GetRoot()->GetDictBy("Names")) - m_pRoot = pDoc->GetRoot()->GetDictBy("Names")->GetDictBy(category); - else - m_pRoot = NULL; + const CFX_ByteString& category) + : m_pRoot(nullptr) { + CPDF_Dictionary* pRoot = pDoc->GetRoot(); + if (!pRoot) + return; + + CPDF_Dictionary* pNames = pRoot->GetDictBy("Names"); + if (!pNames) + return; + + m_pRoot = pNames->GetDictBy(category); } static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, @@ -233,7 +240,7 @@ CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { return SearchNameNode(m_pRoot, csName, nIndex, NULL); } CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, - const CFX_ByteStringC& sName) { + const CFX_ByteString& sName) { CPDF_Object* pValue = LookupValue(sName); if (!pValue) { CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictBy("Dests"); diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h index b8bc56b0cc..c11bf43c4e 100644 --- a/core/fpdfdoc/include/fpdf_doc.h +++ b/core/fpdfdoc/include/fpdf_doc.h @@ -51,12 +51,11 @@ class CFX_RenderDevice; class CPDF_NameTree { public: explicit CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {} - CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& category); + CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteString& category); CPDF_Object* LookupValue(int nIndex, CFX_ByteString& csName) const; CPDF_Object* LookupValue(const CFX_ByteString& csName) const; - CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, - const CFX_ByteStringC& sName); + CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const CFX_ByteString& sName); int GetIndex(const CFX_ByteString& csName) const; size_t GetCount() const; CPDF_Dictionary* GetRoot() const { return m_pRoot; } -- cgit v1.2.3