summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-20 14:33:49 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-20 14:33:49 -0800
commitfcb6398ea511e32a09d192543f70041b82646df1 (patch)
tree5e7809400749292195e47ec24af1018d3b002343
parent49e4932735292790c77b5362603d9f5d7f6adaaa (diff)
downloadpdfium-fcb6398ea511e32a09d192543f70041b82646df1.tar.xz
Merge to XFA: Replace more CFX_MapPtrToPtr.
Original Review URL: https://codereview.chromium.org/1580573002 . (cherry picked from commit a505d9d3e13485e090e50d5d83f882fb707d3f48) R=ochang@chromium.org Review URL: https://codereview.chromium.org/1610163003 .
-rw-r--r--BUILD.gn2
-rw-r--r--core/include/fpdfapi/fpdf_parser.h2
-rw-r--r--core/include/fxcrt/fx_basic.h3
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp32
-rw-r--r--core/src/fpdfdoc/doc_tagged.cpp30
-rw-r--r--core/src/fpdfdoc/tagged_int.h9
-rw-r--r--core/src/fxge/android/fpf_skiafontmgr.cpp23
-rw-r--r--core/src/fxge/android/fpf_skiafontmgr.h6
-rw-r--r--pdfium.gyp2
9 files changed, 50 insertions, 59 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 88619bd536..e0cc2b5b4d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -481,7 +481,6 @@ static_library("fxcrt") {
"core/src/fxcrt/fx_basic_coords.cpp",
"core/src/fxcrt/fx_basic_gcc.cpp",
"core/src/fxcrt/fx_basic_list.cpp",
- "core/src/fxcrt/fx_basic_maps.cpp",
"core/src/fxcrt/fx_basic_memmgr.cpp",
"core/src/fxcrt/fx_basic_plex.cpp",
"core/src/fxcrt/fx_basic_utf.cpp",
@@ -507,6 +506,7 @@ static_library("fxcrt") {
"core/include/fxcrt/fx_arb.h",
"core/src/fxcrt/fx_arabic.cpp",
"core/src/fxcrt/fx_arabic.h",
+ "core/src/fxcrt/fx_basic_maps.cpp",
]
}
configs += [ ":pdfium_config" ]
diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h
index bdddfc37d7..ad4f1f9a9a 100644
--- a/core/include/fpdfapi/fpdf_parser.h
+++ b/core/include/fpdfapi/fpdf_parser.h
@@ -545,7 +545,7 @@ class CPDF_Parser {
FX_DWORD m_dwXrefStartObjNum;
// A map of object numbers to indirect streams. Map owns the streams.
- CFX_MapPtrToPtr m_ObjectStreamMap;
+ std::map<FX_DWORD, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap;
// Mapping of object numbers to offsets. The offsets are relative to the first
// object in the stream.
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 3414dbc13b..3377dec459 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -640,6 +640,7 @@ class CFX_FixedBufGrow {
DataType m_Data[FixedSize];
DataType* m_pData;
};
+#ifdef PDF_ENABLE_XFA
class CFX_MapPtrToPtr {
protected:
struct CAssoc {
@@ -704,7 +705,7 @@ class CFX_MapPtrToPtr {
CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
};
-#ifdef PDF_ENABLE_XFA
+
template <class KeyType, class ValueType>
class CFX_MapPtrTemplate : public CFX_MapPtrToPtr {
public:
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index cd22b31238..97c5a75082 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -161,14 +161,7 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse) {
m_Syntax.m_pFileAccess->Release();
m_Syntax.m_pFileAccess = NULL;
}
- FX_POSITION pos = m_ObjectStreamMap.GetStartPosition();
- while (pos) {
- void* objnum;
- CPDF_StreamAcc* pStream;
- m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream);
- delete pStream;
- }
- m_ObjectStreamMap.RemoveAll();
+ m_ObjectStreamMap.clear();
m_ObjCache.clear();
m_SortedOffset.RemoveAll();
@@ -616,7 +609,7 @@ FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) {
return FALSE;
}
}
- m_ObjectStreamMap.InitHashTable(101, FALSE);
+ m_ObjectStreamMap.clear();
m_bXRefStream = TRUE;
return TRUE;
}
@@ -1252,18 +1245,18 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject(
}
CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) {
- CPDF_StreamAcc* pStreamAcc = nullptr;
- if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc))
- return pStreamAcc;
+ auto it = m_ObjectStreamMap.find(objnum);
+ if (it != m_ObjectStreamMap.end())
+ return it->second.get();
const CPDF_Stream* pStream = ToStream(
m_pDocument ? m_pDocument->GetIndirectObject(objnum, nullptr) : nullptr);
if (!pStream)
return nullptr;
- pStreamAcc = new CPDF_StreamAcc;
+ CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc;
pStreamAcc->LoadAllData(pStream);
- m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc);
+ m_ObjectStreamMap[objnum].reset(pStreamAcc);
return pStreamAcc;
}
@@ -1671,7 +1664,7 @@ FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) {
return FALSE;
}
}
- m_ObjectStreamMap.InitHashTable(101, FALSE);
+ m_ObjectStreamMap.clear();
m_bXRefStream = TRUE;
return TRUE;
}
@@ -1695,14 +1688,7 @@ FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() {
m_Syntax.GetNextChar(ch);
}
m_LastXRefOffset += dwCount;
- FX_POSITION pos = m_ObjectStreamMap.GetStartPosition();
- while (pos) {
- void* objnum;
- CPDF_StreamAcc* pStream;
- m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream);
- delete pStream;
- }
- m_ObjectStreamMap.RemoveAll();
+ m_ObjectStreamMap.clear();
m_ObjCache.clear();
if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp
index d51743b0dc..3510eb6c8e 100644
--- a/core/src/fpdfdoc/doc_tagged.cpp
+++ b/core/src/fpdfdoc/doc_tagged.cpp
@@ -93,7 +93,7 @@ void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
for (i = 0; i < dwKids; i++) {
m_Kids[i] = NULL;
}
- CFX_MapPtrToPtr element_map;
+ std::map<CPDF_Dictionary*, CPDF_StructElementImpl*> element_map;
CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDict("ParentTree");
if (!pParentTree) {
return;
@@ -114,23 +114,25 @@ void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
}
}
}
-CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode(CPDF_Dictionary* pDict,
- CFX_MapPtrToPtr& map,
- int nLevel) {
- if (nLevel > nMaxRecursion) {
+CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode(
+ CPDF_Dictionary* pDict,
+ std::map<CPDF_Dictionary*, CPDF_StructElementImpl*>& map,
+ int nLevel) {
+ if (nLevel > nMaxRecursion)
return NULL;
- }
- CPDF_StructElementImpl* pElement = NULL;
- if (map.Lookup(pDict, (void*&)pElement)) {
- return pElement;
- }
- pElement = new CPDF_StructElementImpl(this, NULL, pDict);
- map.SetAt(pDict, pElement);
+
+ auto it = map.find(pDict);
+ if (it != map.end())
+ return it->second;
+
+ CPDF_StructElementImpl* pElement =
+ new CPDF_StructElementImpl(this, NULL, pDict);
+ map[pDict] = pElement;
CPDF_Dictionary* pParent = pDict->GetDict("P");
if (!pParent || pParent->GetString("Type") == "StructTreeRoot") {
if (!AddTopLevelNode(pDict, pElement)) {
pElement->Release();
- map.RemoveKey(pDict);
+ map.erase(pDict);
}
} else {
CPDF_StructElementImpl* pParentElement =
@@ -148,7 +150,7 @@ CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode(CPDF_Dictionary* pDict,
}
if (!bSave) {
pElement->Release();
- map.RemoveKey(pDict);
+ map.erase(pDict);
}
}
return pElement;
diff --git a/core/src/fpdfdoc/tagged_int.h b/core/src/fpdfdoc/tagged_int.h
index b9ae86bc6a..7dc9549569 100644
--- a/core/src/fpdfdoc/tagged_int.h
+++ b/core/src/fpdfdoc/tagged_int.h
@@ -7,6 +7,8 @@
#ifndef CORE_SRC_FPDFDOC_TAGGED_INT_H_
#define CORE_SRC_FPDFDOC_TAGGED_INT_H_
+#include <map>
+
#include "core/include/fpdfdoc/fpdf_tagged.h"
class CPDF_StructElementImpl;
@@ -24,9 +26,10 @@ class CPDF_StructTreeImpl : public CPDF_StructTree {
void LoadDocTree();
void LoadPageTree(const CPDF_Dictionary* pPageDict);
- CPDF_StructElementImpl* AddPageNode(CPDF_Dictionary* pElement,
- CFX_MapPtrToPtr& map,
- int nLevel = 0);
+ CPDF_StructElementImpl* AddPageNode(
+ CPDF_Dictionary* pElement,
+ std::map<CPDF_Dictionary*, CPDF_StructElementImpl*>& map,
+ int nLevel = 0);
FX_BOOL AddTopLevelNode(CPDF_Dictionary* pDict,
CPDF_StructElementImpl* pElement);
diff --git a/core/src/fxge/android/fpf_skiafontmgr.cpp b/core/src/fxge/android/fpf_skiafontmgr.cpp
index 9dbe35d0e5..d4de2b812e 100644
--- a/core/src/fxge/android/fpf_skiafontmgr.cpp
+++ b/core/src/fxge/android/fpf_skiafontmgr.cpp
@@ -219,14 +219,11 @@ CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() : m_bLoaded(FALSE), m_FTLibrary(NULL) {}
CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() {
void* pkey = NULL;
CFPF_SkiaFont* pValue = NULL;
- FX_POSITION pos = m_FamilyFonts.GetStartPosition();
- while (pos) {
- m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue);
- if (pValue) {
- pValue->Release();
- }
+ for (const auto& pair : m_FamilyFonts) {
+ if (pair.second)
+ pair.second->Release();
}
- m_FamilyFonts.RemoveAll();
+ m_FamilyFonts.clear();
for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) {
CFPF_SkiaFontDescriptor* pFont =
(CFPF_SkiaFontDescriptor*)m_FontFaces.ElementAt(i);
@@ -259,12 +256,10 @@ IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname,
FX_DWORD dwStyle,
FX_DWORD dwMatch) {
FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
- IFPF_Font* pFont = NULL;
- if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
- if (pFont) {
- return pFont->Retain();
- }
- }
+ auto it = m_FamilyFonts.find(dwHash);
+ if (it != m_FamilyFonts.end() && it->second)
+ return it->second->Retain();
+
FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName);
FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName);
@@ -335,7 +330,7 @@ IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname,
(CFPF_SkiaFontDescriptor*)m_FontFaces.ElementAt(nItem);
CFPF_SkiaFont* pFont = new CFPF_SkiaFont;
if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) {
- m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
+ m_FamilyFonts[dwHash] = pFont;
return pFont->Retain();
}
pFont->Release();
diff --git a/core/src/fxge/android/fpf_skiafontmgr.h b/core/src/fxge/android/fpf_skiafontmgr.h
index cd503f58a9..4625e8c605 100644
--- a/core/src/fxge/android/fpf_skiafontmgr.h
+++ b/core/src/fxge/android/fpf_skiafontmgr.h
@@ -9,6 +9,8 @@
#if _FX_OS_ == _FX_ANDROID_
+#include <map>
+
#include "core/include/fxge/fpf.h"
#define FPF_SKIAFONTTYPE_Unknown 0
@@ -16,6 +18,8 @@
#define FPF_SKIAFONTTYPE_File 2
#define FPF_SKIAFONTTYPE_Buffer 3
+class CFPF_SkiaFont;
+
class CFPF_SkiaFontDescriptor {
public:
CFPF_SkiaFontDescriptor()
@@ -110,7 +114,7 @@ class CFPF_SkiaFontMgr : public IFPF_FontMgr {
FX_BOOL m_bLoaded;
CFX_PtrArray m_FontFaces;
FXFT_Library m_FTLibrary;
- CFX_MapPtrToPtr m_FamilyFonts;
+ std::map<FX_DWORD, CFPF_SkiaFont*> m_FamilyFonts;
};
#endif
diff --git a/pdfium.gyp b/pdfium.gyp
index b2cbb30a37..e7ff6b4923 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -461,7 +461,6 @@
'core/src/fxcrt/fx_basic_coords.cpp',
'core/src/fxcrt/fx_basic_gcc.cpp',
'core/src/fxcrt/fx_basic_list.cpp',
- 'core/src/fxcrt/fx_basic_maps.cpp',
'core/src/fxcrt/fx_basic_memmgr.cpp',
'core/src/fxcrt/fx_basic_plex.cpp',
'core/src/fxcrt/fx_basic_utf.cpp',
@@ -482,6 +481,7 @@
'core/include/fxcrt/fx_arb.h',
'core/src/fxcrt/fx_arabic.cpp',
'core/src/fxcrt/fx_arabic.h',
+ 'core/src/fxcrt/fx_basic_maps.cpp',
],
}],
],