diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-08-19 09:49:24 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-08-19 09:49:24 -0700 |
commit | 09d33bcd82a82cb55039d41651df13e17d6c3e59 (patch) | |
tree | 7a748b7570ff6ad0321c4334319bac101da0e6af /xfa/src/fdp | |
parent | 1b0023986bc22ce362097b25deb9746b693ef235 (diff) | |
download | pdfium-09d33bcd82a82cb55039d41651df13e17d6c3e59.tar.xz |
Merge to XFA: CFX_MapByteStringToPtr considered harmful (combo patch).
New manual edits: two unused members deleted, one adapted.
fde_csscache.cpp
fde_csscache.h
fpdfxfa_doc.h
fx_ge_fontmap.cpp
(cherry picked from commit 1d9dbd53b205b2b4d9e75a7eeb95e80837917ea3)
(cherry picked from commit cb4d0ea68308e3c51a6ba9551b393bb2f639afc4)
(cherry picked from commit 9cf44c2ed09a8b2ff243eb6dbb72a8cceae1b5ff)
(cherry picked from commit 2a2a6aa7f51352fc481e78f6ad9d41f2738bcc48)
(cherry picked from commit ce4ffb8183af3fa2bb5133f0f7370a88e064c516)
Original Review URL: https://codereview.chromium.org/1297723002 .
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1301793002 .
Diffstat (limited to 'xfa/src/fdp')
-rw-r--r-- | xfa/src/fdp/src/css/fde_csscache.cpp | 75 | ||||
-rw-r--r-- | xfa/src/fdp/src/css/fde_csscache.h | 2 |
2 files changed, 32 insertions, 45 deletions
diff --git a/xfa/src/fdp/src/css/fde_csscache.cpp b/xfa/src/fdp/src/css/fde_csscache.cpp index 8c5668047f..b04758649f 100644 --- a/xfa/src/fdp/src/css/fde_csscache.cpp +++ b/xfa/src/fdp/src/css/fde_csscache.cpp @@ -17,21 +17,16 @@ _FDE_CSSCACHEITEM::~_FDE_CSSCACHEITEM() { IFDE_CSSStyleSheetCache* IFDE_CSSStyleSheetCache::Create() {
return new CFDE_CSSStyleSheetCache;
}
+
CFDE_CSSStyleSheetCache::CFDE_CSSStyleSheetCache()
: m_pFixedStore(NULL), m_iMaxItems(5) {}
+
CFDE_CSSStyleSheetCache::~CFDE_CSSStyleSheetCache() {
- FX_POSITION pos = m_Stylesheets.GetStartPosition();
- if (pos != NULL) {
- CFX_ByteString szKey;
- void* pValue;
- while (pos != NULL) {
- m_Stylesheets.GetNextAssoc(pos, szKey, pValue);
- FDE_DeleteWith(FDE_CSSCACHEITEM, m_pFixedStore,
- (FDE_LPCSSCACHEITEM)pValue);
- }
- m_Stylesheets.RemoveAll();
+ for (const auto& pair : m_Stylesheets) {
+ FDE_DeleteWith(FDE_CSSCACHEITEM, m_pFixedStore, pair.second);
}
- if (m_pFixedStore != NULL) {
+ m_Stylesheets.clear();
+ if (m_pFixedStore) {
m_pFixedStore->Release();
}
}
@@ -43,9 +38,9 @@ void CFDE_CSSStyleSheetCache::AddStyleSheet(const CFX_ByteStringC& szKey, FX_ALLOCTYPE_Fixed, FX_MAX(10, m_iMaxItems), sizeof(FDE_CSSCACHEITEM));
FXSYS_assert(m_pFixedStore != NULL);
}
- void* pValue = NULL;
- if (m_Stylesheets.Lookup(szKey, pValue)) {
- FDE_LPCSSCACHEITEM pItem = (FDE_LPCSSCACHEITEM)pValue;
+ auto it = m_Stylesheets.find(szKey);
+ if (it != m_Stylesheets.end()) {
+ FDE_LPCSSCACHEITEM pItem = it->second;
if (pItem->pStylesheet != pStyleSheet) {
pItem->pStylesheet->Release();
pItem->pStylesheet = pStyleSheet;
@@ -53,56 +48,48 @@ void CFDE_CSSStyleSheetCache::AddStyleSheet(const CFX_ByteStringC& szKey, pItem->dwActivity = 0;
}
} else {
- while (m_Stylesheets.GetCount() >= m_iMaxItems) {
+ while (static_cast<int32_t>(m_Stylesheets.size()) >= m_iMaxItems) {
RemoveLowestActivityItem();
}
- FDE_LPCSSCACHEITEM pItem =
+ m_Stylesheets[szKey] =
FDE_NewWith(m_pFixedStore) FDE_CSSCACHEITEM(pStyleSheet);
- FXSYS_assert(pItem != NULL);
- m_Stylesheets.SetAt(szKey, pItem);
}
}
IFDE_CSSStyleSheet* CFDE_CSSStyleSheetCache::GetStyleSheet(
const CFX_ByteStringC& szKey) const {
- void* pValue = NULL;
- if (m_Stylesheets.Lookup(szKey, pValue)) {
- FDE_LPCSSCACHEITEM pItem = (FDE_LPCSSCACHEITEM)pValue;
- pItem->dwActivity++;
- pItem->pStylesheet->AddRef();
- return pItem->pStylesheet;
+ auto it = m_Stylesheets.find(szKey);
+ if (it == m_Stylesheets.end()) {
+ return nullptr;
}
- return NULL;
+ FDE_LPCSSCACHEITEM pItem = it->second;
+ pItem->dwActivity++;
+ pItem->pStylesheet->AddRef();
+ return pItem->pStylesheet;
}
void CFDE_CSSStyleSheetCache::RemoveStyleSheet(const CFX_ByteStringC& szKey) {
- void* pValue = NULL;
- if (!m_Stylesheets.Lookup(szKey, pValue)) {
+ auto it = m_Stylesheets.find(szKey);
+ if (it == m_Stylesheets.end()) {
return;
}
- FDE_DeleteWith(FDE_CSSCACHEITEM, m_pFixedStore, (FDE_LPCSSCACHEITEM)pValue);
- m_Stylesheets.RemoveKey(szKey);
+ FDE_DeleteWith(FDE_CSSCACHEITEM, m_pFixedStore, it->second);
+ m_Stylesheets.erase(it);
}
void CFDE_CSSStyleSheetCache::RemoveLowestActivityItem() {
- FX_POSITION pos = m_Stylesheets.GetStartPosition();
- CFX_ByteString szKey;
- void* pValue;
- FDE_LPCSSCACHEITEM pItem = NULL;
- CFX_ByteString szItem;
- while (pos != NULL) {
- m_Stylesheets.GetNextAssoc(pos, szKey, pValue);
- switch (szKey.GetID()) {
+ auto found = m_Stylesheets.end();
+ for (auto it = m_Stylesheets.begin(); it != m_Stylesheets.end(); ++it) {
+ switch (it->first.GetID()) {
case FXBSTR_ID('#', 'U', 'S', 'E'):
case FXBSTR_ID('#', 'A', 'G', 'E'):
continue;
}
- FDE_LPCSSCACHEITEM p = (FDE_LPCSSCACHEITEM)pValue;
- if (pItem == NULL || pItem->dwActivity > p->dwActivity) {
- szItem = szKey;
- pItem = p;
+ if (found == m_Stylesheets.end() ||
+ it->second->dwActivity > found->second->dwActivity) {
+ found = it;
}
}
- if (pItem != NULL) {
- FDE_DeleteWith(FDE_CSSCACHEITEM, m_pFixedStore, pItem);
- m_Stylesheets.RemoveKey(szItem);
+ if (found != m_Stylesheets.end()) {
+ FDE_DeleteWith(FDE_CSSCACHEITEM, m_pFixedStore, found->second);
+ m_Stylesheets.erase(found);
}
}
_FDE_CSSTAGCACHE::_FDE_CSSTAGCACHE(_FDE_CSSTAGCACHE* parent,
diff --git a/xfa/src/fdp/src/css/fde_csscache.h b/xfa/src/fdp/src/css/fde_csscache.h index a5b85b7690..fd113a2159 100644 --- a/xfa/src/fdp/src/css/fde_csscache.h +++ b/xfa/src/fdp/src/css/fde_csscache.h @@ -32,7 +32,7 @@ class CFDE_CSSStyleSheetCache : public IFDE_CSSStyleSheetCache, protected:
void RemoveLowestActivityItem();
- CFX_MapByteStringToPtr m_Stylesheets;
+ std::map<CFX_ByteString, FDE_LPCSSCACHEITEM> m_Stylesheets;
IFX_MEMAllocator* m_pFixedStore;
int32_t m_iMaxItems;
};
|