Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: xfa/fde/css/fde_cssdeclaration.cpp

Issue 1990363003: Use std::unordered_map for CFDE_CSSStyleSheet::m_StringCache (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « xfa/fde/css/fde_cssdeclaration.h ('k') | xfa/fde/css/fde_cssstylesheet.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fde/css/fde_cssdeclaration.cpp
diff --git a/xfa/fde/css/fde_cssdeclaration.cpp b/xfa/fde/css/fde_cssdeclaration.cpp
index f4f55fc0dbf39b25ef72f152c0f72bac6bac0bbd..570b60c6704064e10e3f0501574d121380dcaa34 100644
--- a/xfa/fde/css/fde_cssdeclaration.cpp
+++ b/xfa/fde/css/fde_cssdeclaration.cpp
@@ -53,26 +53,21 @@ const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal(
const FX_WCHAR* pszValue,
int32_t iValueLen) {
ASSERT(iValueLen > 0);
- CFX_MapPtrToPtr* pCache = pArgs->pStringCache;
- void* pKey = NULL;
+ std::unordered_map<uint32_t, FX_WCHAR*>* pCache = pArgs->pStringCache;
+ uint32_t key = 0;
if (pCache) {
- void* pszCached = NULL;
- pKey = (void*)(uintptr_t)FX_HashCode_GetW(
- CFX_WideStringC(pszValue, iValueLen), false);
- if (pCache->Lookup(pKey, pszCached)) {
- return (const FX_WCHAR*)pszCached;
- }
+ key = FX_HashCode_GetW(CFX_WideStringC(pszValue, iValueLen), false);
+ auto it = pCache->find(key);
+ if (it != pCache->end())
+ return it->second;
}
FX_WCHAR* psz =
(FX_WCHAR*)pArgs->pStaticStore->Alloc((iValueLen + 1) * sizeof(FX_WCHAR));
- if (psz == NULL) {
- return NULL;
- }
FXSYS_wcsncpy(psz, pszValue, iValueLen);
psz[iValueLen] = '\0';
- if (pCache) {
- pCache->SetAt(pKey, psz);
- }
+ if (pCache)
+ (*pCache)[key] = psz;
+
return psz;
}
IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue(
« no previous file with comments | « xfa/fde/css/fde_cssdeclaration.h ('k') | xfa/fde/css/fde_cssstylesheet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698