From 6e72b2ecdb95f000dede3c80e0c32496c0b27a18 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 26 Apr 2017 15:14:35 -0700 Subject: Remove more |new|s, part 2 Change-Id: I13b43ceafc6a35bcc1e366546a4a408ea01fe4ab Reviewed-on: https://pdfium-review.googlesource.com/4534 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- core/fpdfdoc/cpdf_bookmark.cpp | 5 +++-- core/fpdfdoc/cpdf_filespec.cpp | 7 +++---- core/fpdfdoc/cpdf_filespec.h | 6 +++--- core/fpdfdoc/cpdf_interform.cpp | 10 +++++++--- 4 files changed, 16 insertions(+), 12 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp index ba1e18c46d..8ca5d128f5 100644 --- a/core/fpdfdoc/cpdf_bookmark.cpp +++ b/core/fpdfdoc/cpdf_bookmark.cpp @@ -7,6 +7,7 @@ #include "core/fpdfdoc/cpdf_bookmark.h" #include +#include #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_string.h" @@ -44,12 +45,12 @@ CFX_WideString CPDF_Bookmark::GetTitle() const { if (!len) return CFX_WideString(); - std::unique_ptr buf(new wchar_t[len]); + std::vector buf(len); for (int i = 0; i < len; i++) { wchar_t w = title[i]; buf[i] = w > 0x20 ? w : 0x20; } - return CFX_WideString(buf.get(), len); + return CFX_WideString(buf.data(), len); } CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp index 086515b9a8..7fe8ec8c03 100644 --- a/core/fpdfdoc/cpdf_filespec.cpp +++ b/core/fpdfdoc/cpdf_filespec.cpp @@ -112,10 +112,9 @@ bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { return true; } -CPDF_FileSpec::CPDF_FileSpec(const CFX_WeakPtr& pPool) { - m_pObj = new CPDF_Dictionary(pPool); - m_pObj->AsDictionary()->SetNewFor("Type", "Filespec"); -} +CPDF_FileSpec::CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {} + +CPDF_FileSpec::~CPDF_FileSpec() {} CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { if (filepath.GetLength() <= 1) diff --git a/core/fpdfdoc/cpdf_filespec.h b/core/fpdfdoc/cpdf_filespec.h index 6266c37a47..ea002f0e22 100644 --- a/core/fpdfdoc/cpdf_filespec.h +++ b/core/fpdfdoc/cpdf_filespec.h @@ -15,8 +15,8 @@ class CPDF_Object; class CPDF_FileSpec { public: - explicit CPDF_FileSpec(const CFX_WeakPtr& pPool); - explicit CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {} + explicit CPDF_FileSpec(CPDF_Object* pObj); + ~CPDF_FileSpec(); // Convert a platform dependent file name into pdf format. static CFX_WideString EncodeFileName(const CFX_WideStringC& filepath); @@ -31,7 +31,7 @@ class CPDF_FileSpec { void SetFileName(const CFX_WideStringC& wsFileName); private: - CPDF_Object* m_pObj; + CPDF_Object* const m_pObj; // not owned. }; #endif // CORE_FPDFDOC_CPDF_FILESPEC_H_ diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index dad25aa037..f498617b27 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -23,6 +23,7 @@ #include "core/fxcrt/fx_codepage.h" #include "core/fxge/cfx_substfont.h" #include "core/fxge/fx_font.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -633,7 +634,7 @@ uint8_t CPDF_InterForm::GetNativeCharSet() { CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) : m_pDocument(pDocument), m_pFormDict(nullptr), - m_pFieldTree(new CFieldTree), + m_pFieldTree(pdfium::MakeUnique()), m_pFormNotify(nullptr) { CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); if (!pRoot) @@ -1198,9 +1199,12 @@ std::unique_ptr CPDF_InterForm::ExportToFDF( pMainDict->SetNewFor("UF", PDF_EncodeText(wsFilePath), false); } else { - CPDF_FileSpec filespec(pDoc->GetByteStringPool()); + auto pNewDict = + pdfium::MakeUnique(pDoc->GetByteStringPool()); + pNewDict->SetNewFor("Type", "Filespec"); + CPDF_FileSpec filespec(pNewDict.get()); filespec.SetFileName(pdf_path); - pMainDict->SetFor("F", pdfium::WrapUnique(filespec.GetObj())); + pMainDict->SetFor("F", std::move(pNewDict)); } } -- cgit v1.2.3