diff options
author | tsepez <tsepez@chromium.org> | 2016-12-14 11:30:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-14 11:30:47 -0800 |
commit | 0d73909e89a5c93917b9cb73fe5c03c484f2793d (patch) | |
tree | 6b3dc490bed3fb2e62bb0bc6c09bcf9fb28f0dfc /core/fxcodec/jbig2 | |
parent | 603f57b85c0643f0598f03b97c4525501f3e1221 (diff) | |
download | pdfium-0d73909e89a5c93917b9cb73fe5c03c484f2793d.tar.xz |
Remove CJBig2_List in favor of std::vector<std::unique_ptr<>>
Review-Url: https://codereview.chromium.org/2578663002
Diffstat (limited to 'core/fxcodec/jbig2')
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.cpp | 26 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.h | 5 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GsidProc.cpp | 14 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_List.h | 54 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_SddProc.cpp | 12 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_SymbolDict.cpp | 14 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_SymbolDict.h | 10 |
7 files changed, 41 insertions, 94 deletions
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 757840598a..109013204e 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -104,7 +104,7 @@ int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { } else { m_pStream->offset(4); } - m_SegmentList.push_back(m_pSegment.release()); + m_SegmentList.push_back(std::move(m_pSegment)); if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && pPause->NeedToPauseNow()) { m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; @@ -129,7 +129,7 @@ int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { } else if (pSegment->m_cFlags.s.type == 51) { break; } - m_SegmentList.push_back(pSegment.release()); + m_SegmentList.push_back(std::move(pSegment)); if (pPause && m_pPause && pPause->NeedToPauseNow()) { m_PauseStep = 3; m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; @@ -143,7 +143,7 @@ int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { int32_t nRet = - parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); + parseSegmentData(m_SegmentList[m_nSegmentDecoded].get(), pPause); if (nRet == JBIG2_END_OF_PAGE || nRet == JBIG2_END_OF_FILE) return JBIG2_SUCCESS; @@ -221,11 +221,9 @@ CJBig2_Segment* CJBig2_Context::findSegmentByNumber(uint32_t dwNumber) { return pSeg; } } - for (size_t i = 0; i < m_SegmentList.size(); ++i) { - CJBig2_Segment* pSeg = m_SegmentList.get(i); - if (pSeg->m_dwNumber == dwNumber) { - return pSeg; - } + for (const auto& pSeg : m_SegmentList) { + if (pSeg->m_dwNumber == dwNumber) + return pSeg.get(); } return nullptr; } @@ -394,7 +392,7 @@ int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, } m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); - m_PageInfoList.push_back(pPageInfo.release()); + m_PageInfoList.push_back(std::move(pPageInfo)); m_bInPage = true; } break; case 49: @@ -923,7 +921,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { } if (pSegment->m_cFlags.s.type != 4) { if (!m_bBufSpecified) { - JBig2PageInfo* pPageInfo = m_PageInfoList.back(); + const auto& pPageInfo = m_PageInfoList.back(); if ((pPageInfo->m_bIsStriped == 1) && (ri.y + ri.height > m_pPage->height())) { m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); @@ -1041,7 +1039,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, } if (pSegment->m_cFlags.s.type != 20) { if (!m_bBufSpecified) { - JBig2PageInfo* pPageInfo = m_PageInfoList.back(); + const auto& pPageInfo = m_PageInfoList.back(); if (pPageInfo->m_bIsStriped == 1 && ri.y + ri.height > m_pPage->height()) { m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); @@ -1108,7 +1106,7 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { if (pSegment->m_cFlags.s.type != 36) { if (!m_bBufSpecified) { - JBig2PageInfo* pPageInfo = m_PageInfoList.back(); + const auto& pPageInfo = m_PageInfoList.back(); if ((pPageInfo->m_bIsStriped == 1) && (m_ri.y + m_ri.height > m_pPage->height())) { m_pPage->expand(m_ri.y + m_ri.height, @@ -1142,7 +1140,7 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, } if (pSegment->m_cFlags.s.type != 36) { if (!m_bBufSpecified) { - JBig2PageInfo* pPageInfo = m_PageInfoList.back(); + JBig2PageInfo* pPageInfo = m_PageInfoList.back().get(); if ((pPageInfo->m_bIsStriped == 1) && (m_ri.y + m_ri.height > m_pPage->height())) { m_pPage->expand(m_ri.y + m_ri.height, @@ -1215,7 +1213,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { m_pStream->offset(2); if (pSegment->m_cFlags.s.type != 40) { if (!m_bBufSpecified) { - JBig2PageInfo* pPageInfo = m_PageInfoList.back(); + JBig2PageInfo* pPageInfo = m_PageInfoList.back().get(); if ((pPageInfo->m_bIsStriped == 1) && (ri.y + ri.height > m_pPage->height())) { m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h index 2de5ebbf2c..cd44a82c61 100644 --- a/core/fxcodec/jbig2/JBig2_Context.h +++ b/core/fxcodec/jbig2/JBig2_Context.h @@ -14,7 +14,6 @@ #include "core/fpdfapi/parser/cpdf_object.h" #include "core/fxcodec/fx_codec_def.h" -#include "core/fxcodec/jbig2/JBig2_List.h" #include "core/fxcodec/jbig2/JBig2_Page.h" #include "core/fxcodec/jbig2/JBig2_Segment.h" @@ -89,8 +88,8 @@ class CJBig2_Context { std::unique_ptr<CJBig2_Context> m_pGlobalContext; std::unique_ptr<CJBig2_BitStream> m_pStream; - CJBig2_List<CJBig2_Segment> m_SegmentList; - CJBig2_List<JBig2PageInfo> m_PageInfoList; + std::vector<std::unique_ptr<CJBig2_Segment>> m_SegmentList; + std::vector<std::unique_ptr<JBig2PageInfo>> m_PageInfoList; std::unique_ptr<CJBig2_Image> m_pPage; size_t m_nSegmentDecoded; bool m_bInPage; diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/fxcodec/jbig2/JBig2_GsidProc.cpp index c5a56b122b..387f8ee511 100644 --- a/core/fxcodec/jbig2/JBig2_GsidProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GsidProc.cpp @@ -7,11 +7,11 @@ #include "core/fxcodec/jbig2/JBig2_GsidProc.h" #include <memory> +#include <vector> #include "core/fxcodec/jbig2/JBig2_BitStream.h" #include "core/fxcodec/jbig2/JBig2_GrdProc.h" #include "core/fxcodec/jbig2/JBig2_Image.h" -#include "core/fxcodec/jbig2/JBig2_List.h" #include "core/fxcrt/fx_basic.h" uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, @@ -40,7 +40,7 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, pGRD->GBAT[7] = -2; } - CJBig2_List<CJBig2_Image> GSPLANES(GSBPP); + std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); for (int32_t i = GSBPP - 1; i >= 0; --i) { CJBig2_Image* pImage = nullptr; FXCODEC_STATUS status = @@ -51,19 +51,17 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, if (!pImage) return nullptr; - GSPLANES.set(i, pImage); - + GSPLANES[i].reset(pImage); if (i < GSBPP - 1) - pImage->composeFrom(0, 0, GSPLANES.get(i + 1), JBIG2_COMPOSE_XOR); + pImage->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR); } std::unique_ptr<uint32_t, FxFreeDeleter> GSVALS( FX_Alloc2D(uint32_t, GSW, GSH)); JBIG2_memset(GSVALS.get(), 0, sizeof(uint32_t) * GSW * GSH); for (uint32_t y = 0; y < GSH; ++y) { for (uint32_t x = 0; x < GSW; ++x) { - for (int32_t i = 0; i < GSBPP; ++i) { - GSVALS.get()[y * GSW + x] |= GSPLANES.get(i)->getPixel(x, y) << i; - } + for (int32_t i = 0; i < GSBPP; ++i) + GSVALS.get()[y * GSW + x] |= GSPLANES[i]->getPixel(x, y) << i; } } return GSVALS.release(); diff --git a/core/fxcodec/jbig2/JBig2_List.h b/core/fxcodec/jbig2/JBig2_List.h deleted file mode 100644 index b021ac3375..0000000000 --- a/core/fxcodec/jbig2/JBig2_List.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXCODEC_JBIG2_JBIG2_LIST_H_ -#define CORE_FXCODEC_JBIG2_JBIG2_LIST_H_ - -#include <stdlib.h> - -#include <vector> - -// A poor man's ScopedVector for pointers of TYPE. -// Owns all the pointers contained within and deletes them on destruction. -template <class TYPE> -class CJBig2_List { - public: - CJBig2_List() {} - explicit CJBig2_List(size_t count) { resize(count); } - - ~CJBig2_List() { clear(); } - - TYPE* get(size_t index) const { return m_vector[index]; } - TYPE* back() const { return m_vector.back(); } - size_t size() const { return m_vector.size(); } - - // Deletes all the pointers contained within. - void clear() { - for (size_t i = 0; i < m_vector.size(); ++i) - delete m_vector[i]; - m_vector.clear(); - } - - // Takes ownership of |pItem|. - void push_back(TYPE* pItem) { m_vector.push_back(pItem); } - - // Takes ownership of |pItem|. - void set(size_t index, TYPE* pItem) { - delete m_vector[index]; - m_vector[index] = pItem; - } - - void resize(size_t count) { - for (size_t i = count; i < size(); ++i) - delete m_vector[i]; - m_vector.resize(count); - } - - private: - std::vector<TYPE*> m_vector; -}; - -#endif // CORE_FXCODEC_JBIG2_JBIG2_LIST_H_ diff --git a/core/fxcodec/jbig2/JBig2_SddProc.cpp b/core/fxcodec/jbig2/JBig2_SddProc.cpp index d27ff680d5..5f23fcf4e1 100644 --- a/core/fxcodec/jbig2/JBig2_SddProc.cpp +++ b/core/fxcodec/jbig2/JBig2_SddProc.cpp @@ -264,9 +264,11 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { if (EXFLAGS[I] && J < SDNUMEXSYMS) { if (I < SDNUMINSYMS) { - pDict->AddImage(SDINSYMS[I] ? new CJBig2_Image(*SDINSYMS[I]) : nullptr); + pDict->AddImage(SDINSYMS[I] + ? pdfium::MakeUnique<CJBig2_Image>(*SDINSYMS[I]) + : nullptr); } else { - pDict->AddImage(SDNEWSYMS[I - SDNUMINSYMS]); + pDict->AddImage(pdfium::WrapUnique(SDNEWSYMS[I - SDNUMINSYMS])); } ++J; } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { @@ -596,9 +598,11 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { if (EXFLAGS[I] && J < SDNUMEXSYMS) { if (I < SDNUMINSYMS) { - pDict->AddImage(SDINSYMS[I] ? new CJBig2_Image(*SDINSYMS[I]) : nullptr); + pDict->AddImage(SDINSYMS[I] + ? pdfium::MakeUnique<CJBig2_Image>(*SDINSYMS[I]) + : nullptr); } else { - pDict->AddImage(SDNEWSYMS[I - SDNUMINSYMS]); + pDict->AddImage(pdfium::WrapUnique(SDNEWSYMS[I - SDNUMINSYMS])); } ++J; } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { diff --git a/core/fxcodec/jbig2/JBig2_SymbolDict.cpp b/core/fxcodec/jbig2/JBig2_SymbolDict.cpp index d4dfa35fe9..c89609577b 100644 --- a/core/fxcodec/jbig2/JBig2_SymbolDict.cpp +++ b/core/fxcodec/jbig2/JBig2_SymbolDict.cpp @@ -8,19 +8,19 @@ #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_memory.h" +#include "third_party/base/ptr_util.h" CJBig2_SymbolDict::CJBig2_SymbolDict() {} CJBig2_SymbolDict::~CJBig2_SymbolDict() {} std::unique_ptr<CJBig2_SymbolDict> CJBig2_SymbolDict::DeepCopy() const { - const CJBig2_SymbolDict* src = this; - std::unique_ptr<CJBig2_SymbolDict> dst(new CJBig2_SymbolDict); - for (size_t i = 0; i < src->m_SDEXSYMS.size(); ++i) { - CJBig2_Image* image = src->m_SDEXSYMS.get(i); - dst->m_SDEXSYMS.push_back(image ? new CJBig2_Image(*image) : nullptr); + auto dst = pdfium::MakeUnique<CJBig2_SymbolDict>(); + for (const auto& image : m_SDEXSYMS) { + dst->m_SDEXSYMS.push_back(image ? pdfium::MakeUnique<CJBig2_Image>(*image) + : nullptr); } - dst->m_gbContext = src->m_gbContext; - dst->m_grContext = src->m_grContext; + dst->m_gbContext = m_gbContext; + dst->m_grContext = m_grContext; return dst; } diff --git a/core/fxcodec/jbig2/JBig2_SymbolDict.h b/core/fxcodec/jbig2/JBig2_SymbolDict.h index 4520f76680..d6b897ce70 100644 --- a/core/fxcodec/jbig2/JBig2_SymbolDict.h +++ b/core/fxcodec/jbig2/JBig2_SymbolDict.h @@ -8,10 +8,10 @@ #define CORE_FXCODEC_JBIG2_JBIG2_SYMBOLDICT_H_ #include <memory> +#include <utility> #include <vector> #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" -#include "core/fxcodec/jbig2/JBig2_List.h" #include "core/fxcrt/fx_basic.h" class CJBig2_Image; @@ -24,10 +24,12 @@ class CJBig2_SymbolDict { std::unique_ptr<CJBig2_SymbolDict> DeepCopy() const; // Takes ownership of |image|. - void AddImage(CJBig2_Image* image) { m_SDEXSYMS.push_back(image); } + void AddImage(std::unique_ptr<CJBig2_Image> image) { + m_SDEXSYMS.push_back(std::move(image)); + } size_t NumImages() const { return m_SDEXSYMS.size(); } - CJBig2_Image* GetImage(size_t index) const { return m_SDEXSYMS.get(index); } + CJBig2_Image* GetImage(size_t index) const { return m_SDEXSYMS[index].get(); } const std::vector<JBig2ArithCtx>& GbContext() const { return m_gbContext; } const std::vector<JBig2ArithCtx>& GrContext() const { return m_grContext; } @@ -42,7 +44,7 @@ class CJBig2_SymbolDict { private: std::vector<JBig2ArithCtx> m_gbContext; std::vector<JBig2ArithCtx> m_grContext; - CJBig2_List<CJBig2_Image> m_SDEXSYMS; + std::vector<std::unique_ptr<CJBig2_Image>> m_SDEXSYMS; }; #endif // CORE_FXCODEC_JBIG2_JBIG2_SYMBOLDICT_H_ |