From a9caab94c1f16929e5acf2676117224617d80f53 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 14 Dec 2016 05:57:10 -0800 Subject: Avoid the ptr.reset(new XXX()) anti-pattern Be suspicious of |new|. This removes some of the easy cases. Review-Url: https://codereview.chromium.org/2571913002 --- core/fpdfdoc/cpdf_variabletext.cpp | 3 ++- core/fpdfdoc/cpvt_sectioninfo.cpp | 6 ++++-- core/fpdfdoc/cpvt_wordinfo.cpp | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp index 5cc7e9bf11..1313516f22 100644 --- a/core/fpdfdoc/cpdf_variabletext.cpp +++ b/core/fpdfdoc/cpdf_variabletext.cpp @@ -15,6 +15,7 @@ #include "core/fpdfdoc/cpvt_wordinfo.h" #include "core/fpdfdoc/csection.h" #include "core/fpdfdoc/ipvt_fontmap.h" +#include "third_party/base/ptr_util.h" namespace { @@ -1096,7 +1097,7 @@ bool CPDF_VariableText::IsLatinWord(uint16_t word) { CPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() { if (!m_pVTIterator) - m_pVTIterator.reset(new CPDF_VariableText::Iterator(this)); + m_pVTIterator = pdfium::MakeUnique(this); return m_pVTIterator.get(); } diff --git a/core/fpdfdoc/cpvt_sectioninfo.cpp b/core/fpdfdoc/cpvt_sectioninfo.cpp index eb5c1bb809..ec0262c1a0 100644 --- a/core/fpdfdoc/cpvt_sectioninfo.cpp +++ b/core/fpdfdoc/cpvt_sectioninfo.cpp @@ -5,6 +5,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/fpdfdoc/cpvt_sectioninfo.h" +#include "third_party/base/ptr_util.h" CPVT_SectionInfo::CPVT_SectionInfo() : rcSection(), nTotalLine(0) {} @@ -21,11 +22,12 @@ void CPVT_SectionInfo::operator=(const CPVT_SectionInfo& other) { rcSection = other.rcSection; nTotalLine = other.nTotalLine; if (other.pSecProps) - pSecProps.reset(new CPVT_SecProps(*other.pSecProps)); + pSecProps = pdfium::MakeUnique(*other.pSecProps); else pSecProps.reset(); + if (other.pWordProps) - pWordProps.reset(new CPVT_WordProps(*other.pWordProps)); + pWordProps = pdfium::MakeUnique(*other.pWordProps); else pWordProps.reset(); } diff --git a/core/fpdfdoc/cpvt_wordinfo.cpp b/core/fpdfdoc/cpvt_wordinfo.cpp index 2303f30032..f1ea11915c 100644 --- a/core/fpdfdoc/cpvt_wordinfo.cpp +++ b/core/fpdfdoc/cpvt_wordinfo.cpp @@ -5,6 +5,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/fpdfdoc/cpvt_wordinfo.h" +#include "third_party/base/ptr_util.h" CPVT_WordInfo::CPVT_WordInfo() : Word(0), @@ -48,7 +49,7 @@ void CPVT_WordInfo::operator=(const CPVT_WordInfo& word) { fWordY = word.fWordY; fWordTail = word.fWordTail; if (word.pWordProps) - pWordProps.reset(new CPVT_WordProps(*word.pWordProps)); + pWordProps = pdfium::MakeUnique(*word.pWordProps); else pWordProps.reset(); } -- cgit v1.2.3