summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-06-10 13:18:06 -0700
committerLei Zhang <thestig@chromium.org>2015-06-10 13:18:06 -0700
commitb3aa96cbee31e81d0a72a61027467a2713654499 (patch)
tree6835a91ba2e959e3428ba08bf5464ca671e5da72
parent35c3163d55bebea8095474181f807ddfb2f4f806 (diff)
downloadpdfium-b3aa96cbee31e81d0a72a61027467a2713654499.tar.xz
Convert CPDF_PatternMap to std::map.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1162123004.
-rw-r--r--core/include/fpdfapi/fpdf_resource.h3
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp92
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h3
3 files changed, 43 insertions, 55 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 60a93e1832..cd190b9d30 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -43,14 +43,13 @@ public:
ObjClass m_Obj;
FX_DWORD m_nCount;
};
-typedef CPDF_CountedObject<CPDF_Pattern*> CPDF_CountedPattern;
typedef CPDF_CountedObject<CPDF_Image*> CPDF_CountedImage;
typedef CPDF_CountedObject<CPDF_IccProfile*> CPDF_CountedICCProfile;
typedef CPDF_CountedObject<CPDF_StreamAcc*> CPDF_CountedStreamAcc;
using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace*>;
+using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern*>;
-typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedPattern*> CPDF_PatternMap;
typedef CFX_MapPtrTemplate<FX_DWORD, CPDF_CountedImage*> CPDF_ImageMap;
typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedICCProfile*> CPDF_IccProfileMap;
typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedStreamAcc*> CPDF_FontFileMap;
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index 81cfd00fe3..b277b3c9a0 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -126,13 +126,11 @@ void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj)
}
CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc)
: m_pPDFDoc(pPDFDoc),
- m_PatternMap(),
m_ImageMap(),
m_IccProfileMap(),
m_FontFileMap(),
m_bForceClear(FALSE)
{
- m_PatternMap.InitHashTable(16);
m_ImageMap.InitHashTable(64);
m_IccProfileMap.InitHashTable(16);
m_FontFileMap.InitHashTable(32);
@@ -142,15 +140,10 @@ CPDF_DocPageData::~CPDF_DocPageData()
{
Clear(FALSE);
Clear(TRUE);
- FX_POSITION pos = m_PatternMap.GetStartPosition();
- while (pos)
- {
- CPDF_Object* ptObj;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
- delete ptData;
- }
- m_PatternMap.RemoveAll();
+
+ for (auto& it : m_PatternMap)
+ delete it.second;
+ m_PatternMap.clear();
for (auto& it : m_FontMap)
delete it.second;
@@ -163,20 +156,17 @@ CPDF_DocPageData::~CPDF_DocPageData()
void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
{
- FX_POSITION pos;
m_bForceClear = bForceRelease;
- pos = m_PatternMap.GetStartPosition();
- while (pos) {
- CPDF_Object* ptObj;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
- if (!ptData->m_Obj) {
+
+ for (auto& it : m_PatternMap) {
+ CPDF_CountedPattern* ptData = it.second;
+ if (!ptData->m_Obj)
continue;
- }
+
if (bForceRelease || ptData->m_nCount < 2) {
ptData->m_Obj->SetForceClear(bForceRelease);
delete ptData->m_Obj;
- ptData->m_Obj = NULL;
+ ptData->m_Obj = nullptr;
}
}
@@ -202,7 +192,7 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
}
}
- pos = m_IccProfileMap.GetStartPosition();
+ FX_POSITION pos = m_IccProfileMap.GetStartPosition();
while (pos) {
CPDF_Stream* ipKey;
CPDF_CountedObject<CPDF_IccProfile*>* ipData;
@@ -471,26 +461,23 @@ void CPDF_DocPageData::ReleaseColorSpace(CPDF_Object* pColorSpace)
CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_AffineMatrix* matrix)
{
- if (!pPatternObj) {
- return NULL;
- }
- CPDF_CountedObject<CPDF_Pattern*>* ptData = NULL;
- if (m_PatternMap.Lookup(pPatternObj, ptData)) {
+ if (!pPatternObj)
+ return nullptr;
+
+ CPDF_CountedPattern* ptData = nullptr;
+ auto it = m_PatternMap.find(pPatternObj);
+ if (it != m_PatternMap.end()) {
+ ptData = it->second;
if (ptData->m_Obj) {
ptData->m_nCount++;
return ptData->m_Obj;
}
}
- FX_BOOL bNew = FALSE;
- if (!ptData) {
- ptData = new CPDF_CountedObject<CPDF_Pattern*>;
- bNew = TRUE;
- }
- CPDF_Pattern* pPattern = NULL;
+ CPDF_Pattern* pPattern = nullptr;
if (bShading) {
pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, matrix);
} else {
- CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : NULL;
+ CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr;
if (pDict) {
int type = pDict->GetInteger(FX_BSTRC("PatternType"));
if (type == 1) {
@@ -500,31 +487,34 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bSh
}
}
}
- if (!pPattern) {
- if (bNew) {
- delete ptData;
- }
- return NULL;
+ if (!pPattern)
+ return nullptr;
+
+ if (!ptData) {
+ ptData = new CPDF_CountedPattern;
+ m_PatternMap[pPatternObj] = ptData;
}
ptData->m_nCount = 2;
ptData->m_Obj = pPattern;
- m_PatternMap.SetAt(pPatternObj, ptData);
return pPattern;
}
+
void CPDF_DocPageData::ReleasePattern(CPDF_Object* pPatternObj)
{
- if (!pPatternObj) {
+ if (!pPatternObj)
return;
- }
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- if (!m_PatternMap.Lookup(pPatternObj, ptData)) {
+
+ auto it = m_PatternMap.find(pPatternObj);
+ if (it == m_PatternMap.end())
return;
- }
+
+ CPDF_CountedPattern* ptData = it->second;
if (ptData->m_Obj && --ptData->m_nCount == 0) {
delete ptData->m_Obj;
- ptData->m_Obj = NULL;
+ ptData->m_Obj = nullptr;
}
}
+
CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream)
{
if (!pImageStream) {
@@ -641,11 +631,9 @@ CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(CPDF_Object* pCSObj)
CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj) const
{
- if (!pPatternObj) return NULL;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- if (m_PatternMap.Lookup(pPatternObj, ptData))
- {
- return ptData;
- }
- return NULL;
+ if (!pPatternObj)
+ return nullptr;
+
+ auto it = m_PatternMap.find(pPatternObj);
+ return it != m_PatternMap.end() ? it->second : nullptr;
}
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index e994576da5..2855969e46 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -388,7 +388,6 @@ class CPDF_DocPageData
CPDF_CountedPattern* FindPatternPtr(CPDF_Object* pPatternObj) const;
CPDF_Document* m_pPDFDoc;
- CPDF_PatternMap m_PatternMap;
CPDF_ImageMap m_ImageMap;
CPDF_IccProfileMap m_IccProfileMap;
CFX_MapByteStringToPtr m_HashProfileMap;
@@ -400,9 +399,11 @@ class CPDF_DocPageData
using CPDF_ColorSpaceMap = std::map<CPDF_Object*, CPDF_CountedColorSpace*>;
using CPDF_FontMap = std::map<CPDF_Dictionary*, CPDF_CountedFont*>;
+ using CPDF_PatternMap = std::map<CPDF_Object*, CPDF_CountedPattern*>;
CPDF_ColorSpaceMap m_ColorSpaceMap;
CPDF_FontMap m_FontMap;
+ CPDF_PatternMap m_PatternMap;
};
class CPDF_Function