diff options
author | tsepez <tsepez@chromium.org> | 2016-11-21 17:47:29 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-21 17:47:29 -0800 |
commit | 12ff1eba3eaa4a27089f1837a0826dfcac163db2 (patch) | |
tree | d1aafa004d88a4de7af2d4eb430ebb8b198fcaea /core/fpdfapi/page | |
parent | 8edd6d72afec2bcc2247dd85edec99d156f13870 (diff) | |
download | pdfium-12ff1eba3eaa4a27089f1837a0826dfcac163db2.tar.xz |
Avoid calls to WrapUnique in CPDF_streamparser
Review-Url: https://codereview.chromium.org/2520953004
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 16 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamparser.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/page/pageint.h | 7 |
3 files changed, 12 insertions, 16 deletions
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 8c6038d626..2bc80cc5c9 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -630,8 +630,8 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { void CPDF_StreamContentParser::Handle_BeginImage() { FX_FILESIZE savePos = m_pSyntax->GetPos(); - CPDF_Dictionary* pDict = - new CPDF_Dictionary(m_pDocument->GetByteStringPool()); + auto pDict = + pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); while (1) { CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); if (type == CPDF_StreamParser::Keyword) { @@ -639,7 +639,6 @@ void CPDF_StreamContentParser::Handle_BeginImage() { m_pSyntax->GetWordSize()); if (bsKeyword != "ID") { m_pSyntax->SetPos(savePos); - delete pDict; return; } } @@ -657,7 +656,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { pDict->SetFor(key, std::move(pObj)); } } - ReplaceAbbr(pDict); + ReplaceAbbr(pDict.get()); CPDF_Object* pCSObj = nullptr; if (pDict->KeyExist("ColorSpace")) { pCSObj = pDict->GetDirectObjectFor("ColorSpace"); @@ -671,9 +670,8 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } } pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); - std::unique_ptr<CPDF_Stream> pStream( - m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); - bool bGaveDictAway = !!pStream; + std::unique_ptr<CPDF_Stream> pStream = + m_pSyntax->ReadInlineStream(m_pDocument, std::move(pDict), pCSObj); while (1) { CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); if (type == CPDF_StreamParser::EndOfData) { @@ -687,9 +685,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { break; } } - CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); - if (!pImgObj && !bGaveDictAway) - delete pDict; + AddImage(std::move(pStream)); } void CPDF_StreamContentParser::Handle_BeginMarkedContent() { diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp index 2901d3b50b..7b0bf6ae03 100644 --- a/core/fpdfapi/page/cpdf_streamparser.cpp +++ b/core/fpdfapi/page/cpdf_streamparser.cpp @@ -128,7 +128,7 @@ CPDF_StreamParser::~CPDF_StreamParser() {} std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( CPDF_Document* pDoc, - CPDF_Dictionary* pDict, + std::unique_ptr<CPDF_Dictionary> pDict, CPDF_Object* pCSObj) { if (m_Pos == m_Size) return nullptr; @@ -231,8 +231,7 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( m_Pos += dwStreamSize; } pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize); - return pdfium::MakeUnique<CPDF_Stream>(pData, dwStreamSize, - pdfium::WrapUnique(pDict)); + return pdfium::MakeUnique<CPDF_Stream>(pData, dwStreamSize, std::move(pDict)); } CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { diff --git a/core/fpdfapi/page/pageint.h b/core/fpdfapi/page/pageint.h index cf3522d44a..49a4845e96 100644 --- a/core/fpdfapi/page/pageint.h +++ b/core/fpdfapi/page/pageint.h @@ -61,9 +61,10 @@ class CPDF_StreamParser { std::unique_ptr<CPDF_Object> GetObject() { return std::move(m_pLastObj); } std::unique_ptr<CPDF_Object> ReadNextObject(bool bAllowNestedArray, uint32_t dwInArrayLevel); - std::unique_ptr<CPDF_Stream> ReadInlineStream(CPDF_Document* pDoc, - CPDF_Dictionary* pDict, - CPDF_Object* pCSObj); + std::unique_ptr<CPDF_Stream> ReadInlineStream( + CPDF_Document* pDoc, + std::unique_ptr<CPDF_Dictionary> pDict, + CPDF_Object* pCSObj); private: friend class cpdf_streamparser_ReadHexString_Test; |