From 7b9d82312413a3cd2dc7422313bb634eaa687a87 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 3 Apr 2017 14:53:01 -0700 Subject: Use unique_ptr in cpdf_type3cache.h. Change-Id: Iaea91df0300b55e35cbfd9b3f3389b3e291eae9b Reviewed-on: https://pdfium-review.googlesource.com/3618 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/render/cpdf_type3cache.cpp | 14 ++++++-------- core/fpdfapi/render/cpdf_type3cache.h | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp index d11103d014..b7a4cb808f 100644 --- a/core/fpdfapi/render/cpdf_type3cache.cpp +++ b/core/fpdfapi/render/cpdf_type3cache.cpp @@ -15,6 +15,7 @@ #include "core/fpdfapi/render/cpdf_type3glyphs.h" #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" +#include "third_party/base/ptr_util.h" namespace { @@ -81,11 +82,7 @@ int DetectFirstLastScan(const CFX_RetainPtr& pBitmap, CPDF_Type3Cache::CPDF_Type3Cache(CPDF_Type3Font* pFont) : m_pFont(pFont) {} -CPDF_Type3Cache::~CPDF_Type3Cache() { - for (const auto& pair : m_SizeMap) - delete pair.second; - m_SizeMap.clear(); -} +CPDF_Type3Cache::~CPDF_Type3Cache() {} CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(uint32_t charcode, const CFX_Matrix* pMatrix, @@ -99,10 +96,11 @@ CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(uint32_t charcode, CPDF_Type3Glyphs* pSizeCache; auto it = m_SizeMap.find(FaceGlyphsKey); if (it == m_SizeMap.end()) { - pSizeCache = new CPDF_Type3Glyphs; - m_SizeMap[FaceGlyphsKey] = pSizeCache; + auto pNew = pdfium::MakeUnique(); + pSizeCache = pNew.get(); + m_SizeMap[FaceGlyphsKey] = std::move(pNew); } else { - pSizeCache = it->second; + pSizeCache = it->second.get(); } auto it2 = pSizeCache->m_GlyphMap.find(charcode); if (it2 != pSizeCache->m_GlyphMap.end()) diff --git a/core/fpdfapi/render/cpdf_type3cache.h b/core/fpdfapi/render/cpdf_type3cache.h index 0b3cdcbfa4..dc3e91b359 100644 --- a/core/fpdfapi/render/cpdf_type3cache.h +++ b/core/fpdfapi/render/cpdf_type3cache.h @@ -8,6 +8,7 @@ #define CORE_FPDFAPI_RENDER_CPDF_TYPE3CACHE_H_ #include +#include #include "core/fpdfapi/font/cpdf_type3font.h" #include "core/fxcrt/cfx_retain_ptr.h" @@ -38,7 +39,7 @@ class CPDF_Type3Cache : public CFX_Retainable { float retinaScaleY); CPDF_Type3Font* const m_pFont; - std::map m_SizeMap; + std::map> m_SizeMap; }; #endif // CORE_FPDFAPI_RENDER_CPDF_TYPE3CACHE_H_ -- cgit v1.2.3