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 /core/fpdfapi/render/cpdf_pagerendercache.cpp | |
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>
Diffstat (limited to 'core/fpdfapi/render/cpdf_pagerendercache.cpp')
-rw-r--r-- | core/fpdfapi/render/cpdf_pagerendercache.cpp | 27 |
1 files changed, 9 insertions, 18 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(); |