summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/cpdf_docrenderdata.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-03 14:51:26 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-03 21:52:09 +0000
commit05e6a807311df5c3dfc4cafa56b85614f9bae6d3 (patch)
tree42abc36d38fe479e7b32c13b401c53cb3bd13be3 /core/fpdfapi/render/cpdf_docrenderdata.cpp
parent3a1d9b48cb5485cdb93f1cc9857e5d829868629c (diff)
downloadpdfium-05e6a807311df5c3dfc4cafa56b85614f9bae6d3.tar.xz
RefCount CPDF_Type3Cache all the time.chromium/3062
Prefer internal refcounts to external scheme. Change-Id: Ia99d5fc635a51a38f41b1d64ea44d8202685ddc7 Reviewed-on: https://pdfium-review.googlesource.com/3617 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/render/cpdf_docrenderdata.cpp')
-rw-r--r--core/fpdfapi/render/cpdf_docrenderdata.cpp35
1 files changed, 12 insertions, 23 deletions
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index 39d1fcd0b4..2d0bca4497 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -32,10 +32,7 @@ CPDF_DocRenderData::~CPDF_DocRenderData() {
void CPDF_DocRenderData::Clear(bool bRelease) {
for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) {
auto curr_it = it++;
- CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second;
- if (bRelease || cache->use_count() < 2) {
- delete cache->get();
- delete cache;
+ if (bRelease || curr_it->second->HasOneRef()) {
m_Type3FaceMap.erase(curr_it);
}
}
@@ -47,29 +44,21 @@ void CPDF_DocRenderData::Clear(bool bRelease) {
}
}
-CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont) {
- CPDF_CountedObject<CPDF_Type3Cache>* pCache;
+CFX_RetainPtr<CPDF_Type3Cache> CPDF_DocRenderData::GetCachedType3(
+ CPDF_Type3Font* pFont) {
auto it = m_Type3FaceMap.find(pFont);
- if (it == m_Type3FaceMap.end()) {
- pCache = new CPDF_CountedObject<CPDF_Type3Cache>(
- pdfium::MakeUnique<CPDF_Type3Cache>(pFont));
- m_Type3FaceMap[pFont] = pCache;
- } else {
- pCache = it->second;
- }
- return pCache->AddRef();
+ if (it != m_Type3FaceMap.end())
+ return it->second;
+
+ auto pCache = pdfium::MakeRetain<CPDF_Type3Cache>(pFont);
+ m_Type3FaceMap[pFont] = pCache;
+ return pCache;
}
-void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) {
+void CPDF_DocRenderData::MaybePurgeCachedType3(CPDF_Type3Font* pFont) {
auto it = m_Type3FaceMap.find(pFont);
- if (it != m_Type3FaceMap.end()) {
- it->second->RemoveRef();
- if (it->second->use_count() < 2) {
- delete it->second->get();
- delete it->second;
- m_Type3FaceMap.erase(it);
- }
- }
+ if (it != m_Type3FaceMap.end() && it->second->HasOneRef())
+ m_Type3FaceMap.erase(it);
}
CFX_RetainPtr<CPDF_TransferFunc> CPDF_DocRenderData::GetTransferFunc(