From a0a69233cafa0ec22fd6c776851e3ee069ca66bf Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 1 May 2017 11:39:33 -0700 Subject: Remove more |new|s, part 5 Many of these are already unique_ptrs. Change-Id: I3695d4ff5a8f7483ad994ac7657897fd55069cd5 Reviewed-on: https://pdfium-review.googlesource.com/4690 Commit-Queue: dsinclair Reviewed-by: dsinclair --- core/fxcrt/xml/cfx_saxreader.cpp | 2 +- core/fxge/cfx_unicodeencodingex.h | 4 ++-- core/fxge/ge/cfx_facecache.cpp | 5 +++-- core/fxge/ge/cfx_fontcache.cpp | 6 ++++-- core/fxge/ge/cfx_unicodeencodingex.cpp | 17 +++++++++++------ core/fxge/ge/fx_ge_linux.cpp | 6 ++++-- fxbarcode/oned/BC_OneDimWriter.cpp | 4 ++-- xfa/fgas/font/cfgas_gefont.cpp | 11 +++++------ xfa/fwl/cfwl_caret.cpp | 2 +- xfa/fxfa/parser/cxfa_resolveprocessor.cpp | 2 +- 10 files changed, 34 insertions(+), 25 deletions(-) diff --git a/core/fxcrt/xml/cfx_saxreader.cpp b/core/fxcrt/xml/cfx_saxreader.cpp index 13efdccdda..c345c0c038 100644 --- a/core/fxcrt/xml/cfx_saxreader.cpp +++ b/core/fxcrt/xml/cfx_saxreader.cpp @@ -199,7 +199,7 @@ int32_t CFX_SAXReader::StartParse( m_bCharData = false; m_dwDataOffset = 0; m_dwParseMode = dwParseMode; - m_Stack.emplace(new CFX_SAXItem(++m_dwItemID)); + m_Stack.push(pdfium::MakeUnique(++m_dwItemID)); return 0; } diff --git a/core/fxge/cfx_unicodeencodingex.h b/core/fxge/cfx_unicodeencodingex.h index 21deb44d79..e62410a122 100644 --- a/core/fxge/cfx_unicodeencodingex.h +++ b/core/fxge/cfx_unicodeencodingex.h @@ -30,8 +30,8 @@ class CFX_UnicodeEncodingEx : public CFX_UnicodeEncoding { uint32_t m_nEncodingID; }; -CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx( +std::unique_ptr FX_CreateFontEncodingEx( CFX_Font* pFont, - uint32_t nEncodingID = FXFM_ENCODING_NONE); + uint32_t nEncodingID); #endif // CORE_FXGE_CFX_UNICODEENCODINGEX_H_ diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp index 0969cdf10c..5ad7bdd99a 100644 --- a/core/fxge/ge/cfx_facecache.cpp +++ b/core/fxge/ge/cfx_facecache.cpp @@ -396,8 +396,9 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( CFX_SizeGlyphCache* pSizeCache; auto it = m_SizeMap.find(FaceGlyphsKey); if (it == m_SizeMap.end()) { - pSizeCache = new CFX_SizeGlyphCache; - m_SizeMap[FaceGlyphsKey] = std::unique_ptr(pSizeCache); + auto pNewCache = pdfium::MakeUnique(); + pSizeCache = pNewCache.get(); + m_SizeMap[FaceGlyphsKey] = std::move(pNewCache); } else { pSizeCache = it->second.get(); } diff --git a/core/fxge/ge/cfx_fontcache.cpp b/core/fxge/ge/cfx_fontcache.cpp index 1599c30b93..5ccac8cfbc 100644 --- a/core/fxge/ge/cfx_fontcache.cpp +++ b/core/fxge/ge/cfx_fontcache.cpp @@ -38,8 +38,10 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(const CFX_Font* pFont) { auto counted_face_cache = pdfium::MakeUnique(); counted_face_cache->m_nCount = 2; - CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); - counted_face_cache->m_Obj.reset(face_cache); + auto new_cache = + pdfium::MakeUnique(bExternal ? nullptr : face); + CFX_FaceCache* face_cache = new_cache.get(); + counted_face_cache->m_Obj = std::move(new_cache); map[face] = std::move(counted_face_cache); return face_cache; } diff --git a/core/fxge/ge/cfx_unicodeencodingex.cpp b/core/fxge/ge/cfx_unicodeencodingex.cpp index cd7625fb17..3f28d4295e 100644 --- a/core/fxge/ge/cfx_unicodeencodingex.cpp +++ b/core/fxge/ge/cfx_unicodeencodingex.cpp @@ -6,9 +6,12 @@ #include "core/fxge/cfx_unicodeencodingex.h" +#include + #include "core/fpdfapi/font/cpdf_font.h" #include "core/fxge/fx_font.h" #include "core/fxge/fx_freetype.h" +#include "third_party/base/ptr_util.h" namespace { @@ -22,11 +25,12 @@ const uint32_t g_EncodingID[] = { FXFM_ENCODING_APPLE_ROMAN, }; -CFX_UnicodeEncodingEx* FXFM_CreateFontEncoding(CFX_Font* pFont, - uint32_t nEncodingID) { +std::unique_ptr FXFM_CreateFontEncoding( + CFX_Font* pFont, + uint32_t nEncodingID) { if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID)) return nullptr; - return new CFX_UnicodeEncodingEx(pFont, nEncodingID); + return pdfium::MakeUnique(pFont, nEncodingID); } } // namespace @@ -80,8 +84,9 @@ uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(wchar_t Unicode) const { return CPDF_Font::kInvalidCharCode; } -CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, - uint32_t nEncodingID) { +std::unique_ptr FX_CreateFontEncodingEx( + CFX_Font* pFont, + uint32_t nEncodingID) { if (!pFont || !pFont->GetFace()) return nullptr; @@ -89,7 +94,7 @@ CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, return FXFM_CreateFontEncoding(pFont, nEncodingID); for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { - CFX_UnicodeEncodingEx* pFontEncoding = + std::unique_ptr pFontEncoding = FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); if (pFontEncoding) return pFontEncoding; diff --git a/core/fxge/ge/fx_ge_linux.cpp b/core/fxge/ge/fx_ge_linux.cpp index b216e12127..4e4b2050e9 100644 --- a/core/fxge/ge/fx_ge_linux.cpp +++ b/core/fxge/ge/fx_ge_linux.cpp @@ -5,11 +5,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include +#include #include "core/fxcrt/fx_codepage.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/ge/cfx_folderfontinfo.h" #include "core/fxge/ifx_systemfontinfo.h" +#include "third_party/base/ptr_util.h" #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ namespace { @@ -145,14 +147,14 @@ bool CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) { std::unique_ptr IFX_SystemFontInfo::CreateDefault( const char** pUserPaths) { - CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo; + auto pInfo = pdfium::MakeUnique(); if (!pInfo->ParseFontCfg(pUserPaths)) { pInfo->AddPath("/usr/share/fonts"); pInfo->AddPath("/usr/share/X11/fonts/Type1"); pInfo->AddPath("/usr/share/X11/fonts/TTF"); pInfo->AddPath("/usr/local/share/fonts"); } - return std::unique_ptr(pInfo); + return std::move(pInfo); } void CFX_GEModule::InitPlatform() { diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp index b898340519..14c5911f95 100644 --- a/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/fxbarcode/oned/BC_OneDimWriter.cpp @@ -135,8 +135,8 @@ void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString& text, float geWidth, int32_t fontSize, float& charsLen) { - std::unique_ptr encoding( - FX_CreateFontEncodingEx(cFont)); + std::unique_ptr encoding = + FX_CreateFontEncodingEx(cFont, FXFM_ENCODING_NONE); int32_t length = text.GetLength(); uint32_t* pCharCode = FX_Alloc(uint32_t, text.GetLength()); diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index ab773698e7..b1bd769336 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp @@ -160,12 +160,11 @@ bool CFGAS_GEFont::InitFont() { if (!m_pFont) return false; - if (!m_pFontEncoding) { - m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); - if (!m_pFontEncoding) - return false; - } - return true; + if (m_pFontEncoding) + return true; + + m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont, FXFM_ENCODING_NONE); + return !!m_pFontEncoding; } CFX_RetainPtr CFGAS_GEFont::Derive(uint32_t dwFontStyles, diff --git a/xfa/fwl/cfwl_caret.cpp b/xfa/fwl/cfwl_caret.cpp index da57cb408c..a6ea9ddb56 100644 --- a/xfa/fwl/cfwl_caret.cpp +++ b/xfa/fwl/cfwl_caret.cpp @@ -25,7 +25,7 @@ CFWL_Caret::CFWL_Caret(const CFWL_App* app, std::unique_ptr properties, CFWL_Widget* pOuter) : CFWL_Widget(app, std::move(properties), pOuter), - m_pTimer(new CFWL_Caret::Timer(this)), + m_pTimer(pdfium::MakeUnique(this)), m_pTimerInfo(nullptr) { SetStates(FWL_STATE_CAT_HightLight); } diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp index 14adc7793e..d17a1bab50 100644 --- a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp @@ -23,7 +23,7 @@ #include "xfa/fxfa/parser/xfa_utils.h" CXFA_ResolveProcessor::CXFA_ResolveProcessor() - : m_iCurStart(0), m_pNodeHelper(new CXFA_NodeHelper) {} + : m_iCurStart(0), m_pNodeHelper(pdfium::MakeUnique()) {} CXFA_ResolveProcessor::~CXFA_ResolveProcessor() {} -- cgit v1.2.3