diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-02 19:43:32 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-02 19:43:32 +0000 |
commit | 7f47c50227fb4af93b58c6687786130c42b76333 (patch) | |
tree | ca24aa1921c94487ccfb5cab2c7a9111062497d5 | |
parent | 66601c4c3d89afc6b9b41a5d14359fe94222cc3a (diff) | |
download | pdfium-7f47c50227fb4af93b58c6687786130c42b76333.tar.xz |
Use smart pointers in CPDF_PageRenderCache.
Use std::unique_ptr and MaybeOwned, instead of manual memory management.
Change-Id: I5f08abd869245fb55b7e868621369ff3ea34146f
Reviewed-on: https://pdfium-review.googlesource.com/43211
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r-- | core/fpdfapi/render/cpdf_pagerendercache.cpp | 27 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_pagerendercache.h | 14 |
2 files changed, 17 insertions, 24 deletions
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.cpp b/core/fpdfapi/render/cpdf_pagerendercache.cpp index dfd05bc494..f58837a794 100644 --- a/core/fpdfapi/render/cpdf_pagerendercache.cpp +++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp @@ -28,17 +28,9 @@ struct CacheInfo { } // namespace -CPDF_PageRenderCache::CPDF_PageRenderCache(CPDF_Page* pPage) - : m_pPage(pPage), - m_pCurImageCacheEntry(nullptr), - m_nTimeCount(0), - m_nCacheSize(0), - m_bCurFindCache(false) {} - -CPDF_PageRenderCache::~CPDF_PageRenderCache() { - for (const auto& it : m_ImageCache) - delete it.second; -} +CPDF_PageRenderCache::CPDF_PageRenderCache(CPDF_Page* pPage) : m_pPage(pPage) {} + +CPDF_PageRenderCache::~CPDF_PageRenderCache() = default; void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) { if (m_nCacheSize <= (uint32_t)dwLimitCacheSize) @@ -76,7 +68,6 @@ void CPDF_PageRenderCache::ClearImageCacheEntry(CPDF_Stream* pStream) { return; m_nCacheSize -= it->second->EstimateSize(); - delete it->second; m_ImageCache.erase(it); } @@ -90,10 +81,10 @@ bool CPDF_PageRenderCache::StartGetCachedBitmap( const auto it = m_ImageCache.find(pStream); m_bCurFindCache = it != m_ImageCache.end(); if (m_bCurFindCache) { - m_pCurImageCacheEntry = it->second; + m_pCurImageCacheEntry = it->second.get(); } else { - m_pCurImageCacheEntry = - new CPDF_ImageCacheEntry(m_pPage->GetDocument(), pImage); + m_pCurImageCacheEntry = pdfium::MakeUnique<CPDF_ImageCacheEntry>( + m_pPage->GetDocument(), pImage); } CPDF_DIBBase::LoadState ret = m_pCurImageCacheEntry->StartGetCachedBitmap( pRenderStatus->GetFormResource(), m_pPage->m_pPageResources.Get(), bStdCS, @@ -103,7 +94,7 @@ bool CPDF_PageRenderCache::StartGetCachedBitmap( m_nTimeCount++; if (!m_bCurFindCache) - m_ImageCache[pStream] = m_pCurImageCacheEntry; + m_ImageCache[pStream] = m_pCurImageCacheEntry.Release(); if (ret == CPDF_DIBBase::LoadState::kFail) m_nCacheSize += m_pCurImageCacheEntry->EstimateSize(); @@ -120,7 +111,7 @@ bool CPDF_PageRenderCache::Continue(PauseIndicatorIface* pPause, m_nTimeCount++; if (!m_bCurFindCache) { m_ImageCache[m_pCurImageCacheEntry->GetImage()->GetStream()] = - m_pCurImageCacheEntry; + m_pCurImageCacheEntry.Release(); } m_nCacheSize += m_pCurImageCacheEntry->EstimateSize(); return false; @@ -133,7 +124,7 @@ void CPDF_PageRenderCache::ResetBitmap(const RetainPtr<CPDF_Image>& pImage) { if (it == m_ImageCache.end()) return; - pEntry = it->second; + pEntry = it->second.get(); m_nCacheSize -= pEntry->EstimateSize(); pEntry->Reset(nullptr); m_nCacheSize += pEntry->EstimateSize(); diff --git a/core/fpdfapi/render/cpdf_pagerendercache.h b/core/fpdfapi/render/cpdf_pagerendercache.h index 8f0cb59414..5cfdebb812 100644 --- a/core/fpdfapi/render/cpdf_pagerendercache.h +++ b/core/fpdfapi/render/cpdf_pagerendercache.h @@ -8,8 +8,10 @@ #define CORE_FPDFAPI_RENDER_CPDF_PAGERENDERCACHE_H_ #include <map> +#include <memory> #include "core/fxcrt/fx_system.h" +#include "core/fxcrt/maybe_owned.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" @@ -30,7 +32,7 @@ class CPDF_PageRenderCache { void ResetBitmap(const RetainPtr<CPDF_Image>& pImage); CPDF_Page* GetPage() const { return m_pPage.Get(); } CPDF_ImageCacheEntry* GetCurImageCacheEntry() const { - return m_pCurImageCacheEntry; + return m_pCurImageCacheEntry.Get(); } bool StartGetCachedBitmap(const RetainPtr<CPDF_Image>& pImage, @@ -45,11 +47,11 @@ class CPDF_PageRenderCache { void ClearImageCacheEntry(CPDF_Stream* pStream); UnownedPtr<CPDF_Page> const m_pPage; - CPDF_ImageCacheEntry* m_pCurImageCacheEntry; - std::map<CPDF_Stream*, CPDF_ImageCacheEntry*> m_ImageCache; - uint32_t m_nTimeCount; - uint32_t m_nCacheSize; - bool m_bCurFindCache; + std::map<CPDF_Stream*, std::unique_ptr<CPDF_ImageCacheEntry>> m_ImageCache; + MaybeOwned<CPDF_ImageCacheEntry> m_pCurImageCacheEntry; + uint32_t m_nTimeCount = 0; + uint32_t m_nCacheSize = 0; + bool m_bCurFindCache = false; }; #endif // CORE_FPDFAPI_RENDER_CPDF_PAGERENDERCACHE_H_ |