From 9b671ace8aec906683b05399cf8a2882ed8ef7b6 Mon Sep 17 00:00:00 2001 From: weili Date: Mon, 25 Jul 2016 07:40:27 -0700 Subject: Use smart pointers for CFX_Font and CFX_Type3Font classes For the class owned member variables, use std::unique_ptr or std::vector for memory management. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2169793002 --- core/fpdfapi/fpdf_font/cpdf_type3font.cpp | 13 +++++-------- core/fpdfapi/fpdf_font/cpdf_type3font.h | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/fpdf_font/cpdf_type3font.cpp b/core/fpdfapi/fpdf_font/cpdf_type3font.cpp index 6c339ea5a7..8e4ac56884 100644 --- a/core/fpdfapi/fpdf_font/cpdf_type3font.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_type3font.cpp @@ -21,10 +21,7 @@ CPDF_Type3Font::CPDF_Type3Font() FXSYS_memset(m_CharWidthL, 0, sizeof(m_CharWidthL)); } -CPDF_Type3Font::~CPDF_Type3Font() { - for (auto it : m_CacheMap) - delete it.second; -} +CPDF_Type3Font::~CPDF_Type3Font() {} bool CPDF_Type3Font::IsType3Font() const { return true; @@ -94,7 +91,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode, int level) { auto it = m_CacheMap.find(charcode); if (it != m_CacheMap.end()) - return it->second; + return it->second.get(); const FX_CHAR* name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); @@ -116,7 +113,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode, int level) { pNewChar->m_pForm->ParseContent(nullptr, nullptr, pNewChar.get(), level + 1); it = m_CacheMap.find(charcode); if (it != m_CacheMap.end()) - return it->second; + return it->second.get(); FX_FLOAT scale = m_FontMatrix.GetXUnit(); pNewChar->m_Width = (int32_t)(pNewChar->m_Width * scale + 0.5f); @@ -134,8 +131,8 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode, int level) { rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000); ASSERT(!pdfium::ContainsKey(m_CacheMap, charcode)); - CPDF_Type3Char* pCachedChar = pNewChar.release(); - m_CacheMap[charcode] = pCachedChar; + m_CacheMap[charcode] = std::move(pNewChar); + CPDF_Type3Char* pCachedChar = m_CacheMap[charcode].get(); if (pCachedChar->m_pForm->GetPageObjectList()->empty()) pCachedChar->m_pForm.reset(); return pCachedChar; diff --git a/core/fpdfapi/fpdf_font/cpdf_type3font.h b/core/fpdfapi/fpdf_font/cpdf_type3font.h index 70992c9c8c..c5e99534e0 100644 --- a/core/fpdfapi/fpdf_font/cpdf_type3font.h +++ b/core/fpdfapi/fpdf_font/cpdf_type3font.h @@ -8,6 +8,7 @@ #define CORE_FPDFAPI_FPDF_FONT_CPDF_TYPE3FONT_H_ #include +#include #include "core/fpdfapi/fpdf_font/cpdf_simplefont.h" #include "core/fxcrt/include/fx_coordinates.h" @@ -50,7 +51,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont { CPDF_Dictionary* m_pCharProcs; CPDF_Dictionary* m_pPageResources; CPDF_Dictionary* m_pFontResources; - std::map m_CacheMap; + std::map> m_CacheMap; }; #endif // CORE_FPDFAPI_FPDF_FONT_CPDF_TYPE3FONT_H_ -- cgit v1.2.3