summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_docpagedata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page/cpdf_docpagedata.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp52
1 files changed, 14 insertions, 38 deletions
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index a57c42d3cd..5e13740c21 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -96,15 +96,8 @@ void CPDF_DocPageData::Clear(bool bForceRelease) {
for (auto it = m_FontFileMap.begin(); it != m_FontFileMap.end();) {
auto curr_it = it++;
- CPDF_CountedStreamAcc* pCountedFont = curr_it->second;
- if (!pCountedFont->get())
- continue;
-
- if (bForceRelease || pCountedFont->use_count() < 2) {
- delete pCountedFont->get();
- delete pCountedFont;
+ if (bForceRelease || curr_it->second->HasOneRef())
m_FontFileMap.erase(curr_it);
- }
}
m_ImageMap.clear();
@@ -408,11 +401,11 @@ CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
if (it != m_IccProfileMap.end())
return it->second;
- CPDF_StreamAcc accessor;
- accessor.LoadAllData(pProfileStream, false);
+ auto pAccessor = pdfium::MakeRetain<CPDF_StreamAcc>(pProfileStream);
+ pAccessor->LoadAllData(false);
uint8_t digest[20];
- CRYPT_SHA1Generate(accessor.GetData(), accessor.GetSize(), digest);
+ CRYPT_SHA1Generate(pAccessor->GetData(), pAccessor->GetSize(), digest);
CFX_ByteString bsDigest(digest, 20);
auto hash_it = m_HashProfileMap.find(bsDigest);
@@ -422,7 +415,7 @@ CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
return it_copied_stream->second;
}
auto pProfile = pdfium::MakeRetain<CPDF_IccProfile>(
- pProfileStream, accessor.GetData(), accessor.GetSize());
+ pProfileStream, pAccessor->GetData(), pAccessor->GetSize());
m_IccProfileMap[pProfileStream] = pProfile;
m_HashProfileMap[bsDigest] = pProfileStream;
return pProfile;
@@ -435,13 +428,12 @@ void CPDF_DocPageData::MaybePurgeIccProfile(CPDF_Stream* pProfileStream) {
m_IccProfileMap.erase(it);
}
-CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
+CFX_RetainPtr<CPDF_StreamAcc> CPDF_DocPageData::GetFontFileStreamAcc(
CPDF_Stream* pFontStream) {
ASSERT(pFontStream);
-
auto it = m_FontFileMap.find(pFontStream);
if (it != m_FontFileMap.end())
- return it->second->AddRef();
+ return it->second;
CPDF_Dictionary* pFontDict = pFontStream->GetDict();
int32_t org_size = pFontDict->GetIntegerFor("Length1") +
@@ -449,36 +441,20 @@ CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
pFontDict->GetIntegerFor("Length3");
org_size = std::max(org_size, 0);
- auto pFontAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
- pFontAcc->LoadAllData(pFontStream, false, org_size);
-
- CPDF_CountedStreamAcc* pCountedFont =
- new CPDF_CountedStreamAcc(std::move(pFontAcc));
- m_FontFileMap[pFontStream] = pCountedFont;
- return pCountedFont->AddRef();
+ auto pFontAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pFontStream);
+ pFontAcc->LoadAllData(false, org_size);
+ m_FontFileMap[pFontStream] = pFontAcc;
+ return pFontAcc;
}
-void CPDF_DocPageData::ReleaseFontFileStreamAcc(
+void CPDF_DocPageData::MaybePurgeFontFileStreamAcc(
const CPDF_Stream* pFontStream) {
if (!pFontStream)
return;
auto it = m_FontFileMap.find(pFontStream);
- if (it == m_FontFileMap.end())
- return;
-
- CPDF_CountedStreamAcc* pCountedStream = it->second;
- if (!pCountedStream)
- return;
-
- pCountedStream->RemoveRef();
- if (pCountedStream->use_count() > 1)
- return;
-
- // We have item only in m_FontFileMap cache. Clean it.
- delete pCountedStream->get();
- delete pCountedStream;
- m_FontFileMap.erase(it);
+ if (it != m_FontFileMap.end() && it->second->HasOneRef())
+ m_FontFileMap.erase(it);
}
CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(