summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-20 14:06:23 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-20 14:06:23 -0800
commita505d9d3e13485e090e50d5d83f882fb707d3f48 (patch)
tree72c7544f2c52bc22ca92af611cbd7d68f662622b
parent2a312f90dbf5da8b930dee814db786965792961a (diff)
downloadpdfium-a505d9d3e13485e090e50d5d83f882fb707d3f48.tar.xz
Replace more CFX_MapPtrToPtr and remove it.
Still used by XFA, so the merge will make this XFA only. R=ochang@chromium.org Review URL: https://codereview.chromium.org/1580573002 .
-rw-r--r--BUILD.gn1
-rw-r--r--core/include/fpdfapi/fpdf_parser.h2
-rw-r--r--core/include/fxcrt/fx_basic.h64
-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/fxcrt/fx_basic_maps.cpp159
-rw-r--r--core/src/fxge/android/fpf_skiafontmgr.cpp23
-rw-r--r--core/src/fxge/android/fpf_skiafontmgr.h6
-rw-r--r--pdfium.gyp1
10 files changed, 46 insertions, 281 deletions
diff --git a/BUILD.gn b/BUILD.gn
index c16c89a7c8..2d170a2e59 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -451,7 +451,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",
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 0635b0605d..6c4e6ad447 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -572,70 +572,6 @@ class CFX_FixedBufGrow {
DataType m_Data[FixedSize];
DataType* m_pData;
};
-class CFX_MapPtrToPtr {
- protected:
- struct CAssoc {
- CAssoc* pNext;
-
- void* key;
-
- void* value;
- };
-
- public:
- CFX_MapPtrToPtr(int nBlockSize = 10);
-
- ~CFX_MapPtrToPtr();
-
- int GetCount() const { return m_nCount; }
-
- FX_BOOL IsEmpty() const { return m_nCount == 0; }
-
- FX_BOOL Lookup(void* key, void*& rValue) const;
-
- void* GetValueAt(void* key) const;
-
- void*& operator[](void* key);
-
- void SetAt(void* key, void* newValue) { (*this)[key] = newValue; }
-
- FX_BOOL RemoveKey(void* key);
-
- void RemoveAll();
-
- FX_POSITION GetStartPosition() const {
- return (m_nCount == 0) ? NULL : (FX_POSITION)-1;
- }
-
- void GetNextAssoc(FX_POSITION& rNextPosition,
- void*& rKey,
- void*& rValue) const;
-
- FX_DWORD GetHashTableSize() const { return m_nHashTableSize; }
-
- void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
-
- protected:
- CAssoc** m_pHashTable;
-
- FX_DWORD m_nHashTableSize;
-
- int m_nCount;
-
- CAssoc* m_pFreeList;
-
- struct CFX_Plex* m_pBlocks;
-
- int m_nBlockSize;
-
- FX_DWORD HashKey(void* key) const;
-
- CAssoc* NewAssoc();
-
- void FreeAssoc(CAssoc* pAssoc);
-
- CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
-};
class CFX_PtrList {
protected:
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/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp
deleted file mode 100644
index d9b634e649..0000000000
--- a/core/src/fxcrt/fx_basic_maps.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/include/fxcrt/fx_basic.h"
-#include "plex.h"
-
-CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
- : m_pHashTable(NULL),
- m_nHashTableSize(17),
- m_nCount(0),
- m_pFreeList(NULL),
- m_pBlocks(NULL),
- m_nBlockSize(nBlockSize) {
- ASSERT(m_nBlockSize > 0);
-}
-void CFX_MapPtrToPtr::RemoveAll() {
- FX_Free(m_pHashTable);
- m_pHashTable = NULL;
- m_nCount = 0;
- m_pFreeList = NULL;
- m_pBlocks->FreeDataChain();
- m_pBlocks = NULL;
-}
-CFX_MapPtrToPtr::~CFX_MapPtrToPtr() {
- RemoveAll();
- ASSERT(m_nCount == 0);
-}
-FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const {
- return ((FX_DWORD)(uintptr_t)key) >> 4;
-}
-void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition,
- void*& rKey,
- void*& rValue) const {
- ASSERT(m_pHashTable);
- CAssoc* pAssocRet = (CAssoc*)rNextPosition;
- ASSERT(pAssocRet);
- if (pAssocRet == (CAssoc*)-1) {
- for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) {
- if ((pAssocRet = m_pHashTable[nBucket]) != NULL)
- break;
- }
- ASSERT(pAssocRet);
- }
- CAssoc* pAssocNext;
- if ((pAssocNext = pAssocRet->pNext) == NULL) {
- for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1;
- nBucket < m_nHashTableSize; nBucket++) {
- if ((pAssocNext = m_pHashTable[nBucket]) != NULL) {
- break;
- }
- }
- }
- rNextPosition = (FX_POSITION)pAssocNext;
- rKey = pAssocRet->key;
- rValue = pAssocRet->value;
-}
-FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const {
- FX_DWORD nHash;
- CAssoc* pAssoc = GetAssocAt(key, nHash);
- if (!pAssoc) {
- return FALSE;
- }
- rValue = pAssoc->value;
- return TRUE;
-}
-void* CFX_MapPtrToPtr::GetValueAt(void* key) const {
- FX_DWORD nHash;
- CAssoc* pAssoc = GetAssocAt(key, nHash);
- if (!pAssoc) {
- return NULL;
- }
- return pAssoc->value;
-}
-void*& CFX_MapPtrToPtr::operator[](void* key) {
- FX_DWORD nHash;
- CAssoc* pAssoc;
- if ((pAssoc = GetAssocAt(key, nHash)) == NULL) {
- if (!m_pHashTable) {
- InitHashTable(m_nHashTableSize);
- }
- pAssoc = NewAssoc();
- pAssoc->key = key;
- pAssoc->pNext = m_pHashTable[nHash];
- m_pHashTable[nHash] = pAssoc;
- }
- return pAssoc->value;
-}
-CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key,
- FX_DWORD& nHash) const {
- nHash = HashKey(key) % m_nHashTableSize;
- if (!m_pHashTable) {
- return NULL;
- }
- CAssoc* pAssoc;
- for (pAssoc = m_pHashTable[nHash]; pAssoc; pAssoc = pAssoc->pNext) {
- if (pAssoc->key == key)
- return pAssoc;
- }
- return NULL;
-}
-CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() {
- if (!m_pFreeList) {
- CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize,
- sizeof(CFX_MapPtrToPtr::CAssoc));
- CFX_MapPtrToPtr::CAssoc* pAssoc =
- (CFX_MapPtrToPtr::CAssoc*)newBlock->data();
- pAssoc += m_nBlockSize - 1;
- for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
- pAssoc->pNext = m_pFreeList;
- m_pFreeList = pAssoc;
- }
- }
- CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList;
- m_pFreeList = m_pFreeList->pNext;
- m_nCount++;
- ASSERT(m_nCount > 0);
- pAssoc->key = 0;
- pAssoc->value = 0;
- return pAssoc;
-}
-void CFX_MapPtrToPtr::InitHashTable(FX_DWORD nHashSize, FX_BOOL bAllocNow) {
- ASSERT(m_nCount == 0);
- ASSERT(nHashSize > 0);
- FX_Free(m_pHashTable);
- m_pHashTable = NULL;
- if (bAllocNow) {
- m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
- }
- m_nHashTableSize = nHashSize;
-}
-FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) {
- if (!m_pHashTable) {
- return FALSE;
- }
- CAssoc** ppAssocPrev;
- ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize];
- CAssoc* pAssoc;
- for (pAssoc = *ppAssocPrev; pAssoc; pAssoc = pAssoc->pNext) {
- if (pAssoc->key == key) {
- *ppAssocPrev = pAssoc->pNext;
- FreeAssoc(pAssoc);
- return TRUE;
- }
- ppAssocPrev = &pAssoc->pNext;
- }
- return FALSE;
-}
-void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) {
- pAssoc->pNext = m_pFreeList;
- m_pFreeList = pAssoc;
- m_nCount--;
- ASSERT(m_nCount >= 0);
- if (m_nCount == 0) {
- RemoveAll();
- }
-}
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 38244ce233..e6721e7aaa 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -429,7 +429,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',