diff options
author | tsepez <tsepez@chromium.org> | 2016-12-14 05:57:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-14 05:57:10 -0800 |
commit | a9caab94c1f16929e5acf2676117224617d80f53 (patch) | |
tree | d71ff9a82fae6e6080deb76375f43056127b3ee2 /core/fpdfapi/font | |
parent | 992ecf7c189e5cabf43e5ad862511cf63d030966 (diff) | |
download | pdfium-a9caab94c1f16929e5acf2676117224617d80f53.tar.xz |
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
Diffstat (limited to 'core/fpdfapi/font')
-rw-r--r-- | core/fpdfapi/font/cpdf_cidfont.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_font.cpp | 12 | ||||
-rw-r--r-- | core/fpdfapi/font/fpdf_font.cpp | 3 |
3 files changed, 11 insertions, 9 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 0217391c12..91df025e0f 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -19,6 +19,7 @@ #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "third_party/base/numerics/safe_math.h" +#include "third_party/base/ptr_util.h" namespace { @@ -398,7 +399,7 @@ bool CPDF_CIDFont::Load() { CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); if (pmap) { if (CPDF_Stream* pStream = pmap->AsStream()) { - m_pStreamAcc.reset(new CPDF_StreamAcc); + m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>(); m_pStreamAcc->LoadAllData(pStream, false); } else if (pmap->GetString() == "Identity") { #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ @@ -581,7 +582,7 @@ int CPDF_CIDFont::GetGlyphIndex(uint32_t unicode, bool* pVertGlyph) { if (error || !m_Font.GetSubData()) return index; - m_pTTGSUBTable.reset(new CFX_CTTGSUBTable); + m_pTTGSUBTable = pdfium::MakeUnique<CFX_CTTGSUBTable>(); m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); return GetVerticalGlyph(index, pVertGlyph); } diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp index 0b76ceedff..5563202455 100644 --- a/core/fpdfapi/font/cpdf_font.cpp +++ b/core/fpdfapi/font/cpdf_font.cpp @@ -279,7 +279,7 @@ void CPDF_Font::LoadUnicodeMap() const { if (!pStream) { return; } - m_pToUnicodeMap.reset(new CPDF_ToUnicodeMap); + m_pToUnicodeMap = pdfium::MakeUnique<CPDF_ToUnicodeMap>(); m_pToUnicodeMap->Load(pStream); } @@ -324,18 +324,18 @@ std::unique_ptr<CPDF_Font> CPDF_Font::Create(CPDF_Document* pDoc, if (tag == CFX_ByteString(kChineseFontNames[i], 4)) { CPDF_Dictionary* pFontDesc = pFontDict->GetDictFor("FontDescriptor"); if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) - pFont.reset(new CPDF_CIDFont); + pFont = pdfium::MakeUnique<CPDF_CIDFont>(); break; } } if (!pFont) - pFont.reset(new CPDF_TrueTypeFont); + pFont = pdfium::MakeUnique<CPDF_TrueTypeFont>(); } else if (type == "Type3") { - pFont.reset(new CPDF_Type3Font); + pFont = pdfium::MakeUnique<CPDF_Type3Font>(); } else if (type == "Type0") { - pFont.reset(new CPDF_CIDFont); + pFont = pdfium::MakeUnique<CPDF_CIDFont>(); } else { - pFont.reset(new CPDF_Type1Font); + pFont = pdfium::MakeUnique<CPDF_Type1Font>(); } pFont->m_pFontDict = pFontDict; pFont->m_pDocument = pDoc; diff --git a/core/fpdfapi/font/fpdf_font.cpp b/core/fpdfapi/font/fpdf_font.cpp index bf1fac4518..7bbd637177 100644 --- a/core/fpdfapi/font/fpdf_font.cpp +++ b/core/fpdfapi/font/fpdf_font.cpp @@ -24,6 +24,7 @@ #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/fx_freetype.h" #include "third_party/base/numerics/safe_conversions.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" int TT2PDF(int m, FXFT_Face face) { @@ -87,7 +88,7 @@ CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc, uint32_t index, std::unique_ptr<CPDF_Font> pFont) { if (!pdfium::ContainsKey(m_StockMap, pDoc)) - m_StockMap[pDoc].reset(new CFX_StockFontArray); + m_StockMap[pDoc] = pdfium::MakeUnique<CFX_StockFontArray>(); return m_StockMap[pDoc]->SetFont(index, std::move(pFont)); } |