OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fde/css/fde_cssdeclaration.h" | 7 #include "xfa/fde/css/fde_cssdeclaration.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fgas/crt/fgas_system.h" | 10 #include "xfa/fgas/crt/fgas_system.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 wsName = pProperty->pwsName; | 47 wsName = pProperty->pwsName; |
48 wsValue = pProperty->pwsValue; | 48 wsValue = pProperty->pwsValue; |
49 pos = (FX_POSITION)pProperty->pNext; | 49 pos = (FX_POSITION)pProperty->pNext; |
50 } | 50 } |
51 const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal( | 51 const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal( |
52 const FDE_CSSPROPERTYARGS* pArgs, | 52 const FDE_CSSPROPERTYARGS* pArgs, |
53 const FX_WCHAR* pszValue, | 53 const FX_WCHAR* pszValue, |
54 int32_t iValueLen) { | 54 int32_t iValueLen) { |
55 ASSERT(iValueLen > 0); | 55 ASSERT(iValueLen > 0); |
56 CFX_MapPtrToPtr* pCache = pArgs->pStringCache; | 56 std::unordered_map<uint32_t, FX_WCHAR*>* pCache = pArgs->pStringCache; |
57 void* pKey = NULL; | 57 uint32_t key = 0; |
58 if (pCache) { | 58 if (pCache) { |
59 void* pszCached = NULL; | 59 key = FX_HashCode_GetW(CFX_WideStringC(pszValue, iValueLen), false); |
60 pKey = (void*)(uintptr_t)FX_HashCode_GetW( | 60 auto it = pCache->find(key); |
61 CFX_WideStringC(pszValue, iValueLen), false); | 61 if (it != pCache->end()) |
62 if (pCache->Lookup(pKey, pszCached)) { | 62 return it->second; |
63 return (const FX_WCHAR*)pszCached; | |
64 } | |
65 } | 63 } |
66 FX_WCHAR* psz = | 64 FX_WCHAR* psz = |
67 (FX_WCHAR*)pArgs->pStaticStore->Alloc((iValueLen + 1) * sizeof(FX_WCHAR)); | 65 (FX_WCHAR*)pArgs->pStaticStore->Alloc((iValueLen + 1) * sizeof(FX_WCHAR)); |
68 if (psz == NULL) { | |
69 return NULL; | |
70 } | |
71 FXSYS_wcsncpy(psz, pszValue, iValueLen); | 66 FXSYS_wcsncpy(psz, pszValue, iValueLen); |
72 psz[iValueLen] = '\0'; | 67 psz[iValueLen] = '\0'; |
73 if (pCache) { | 68 if (pCache) |
74 pCache->SetAt(pKey, psz); | 69 (*pCache)[key] = psz; |
75 } | 70 |
76 return psz; | 71 return psz; |
77 } | 72 } |
78 IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue( | 73 IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue( |
79 IFX_MemoryAllocator* pStaticStore, | 74 IFX_MemoryAllocator* pStaticStore, |
80 FDE_CSSPRIMITIVETYPE eUnit, | 75 FDE_CSSPRIMITIVETYPE eUnit, |
81 FX_FLOAT fValue) const { | 76 FX_FLOAT fValue) const { |
82 static CFDE_CSSPrimitiveValue s_ZeroValue(FDE_CSSPRIMITIVETYPE_Number, 0.0f); | 77 static CFDE_CSSPrimitiveValue s_ZeroValue(FDE_CSSPRIMITIVETYPE_Number, 0.0f); |
83 if (eUnit == FDE_CSSPRIMITIVETYPE_Number && FXSYS_fabs(fValue) < 0.001f) { | 78 if (eUnit == FDE_CSSPRIMITIVETYPE_Number && FXSYS_fabs(fValue) < 0.001f) { |
84 return &s_ZeroValue; | 79 return &s_ZeroValue; |
85 } | 80 } |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 return FALSE; | 1365 return FALSE; |
1371 } else if (pOverflowY == NULL) { | 1366 } else if (pOverflowY == NULL) { |
1372 pOverflowY = NewEnumValue(pStaticStore, pOverflowX->GetEnum()); | 1367 pOverflowY = NewEnumValue(pStaticStore, pOverflowX->GetEnum()); |
1373 } | 1368 } |
1374 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowX, pOverflowX, | 1369 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowX, pOverflowX, |
1375 bImportant); | 1370 bImportant); |
1376 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowY, pOverflowY, | 1371 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowY, pOverflowY, |
1377 bImportant); | 1372 bImportant); |
1378 return TRUE; | 1373 return TRUE; |
1379 } | 1374 } |
OLD | NEW |