summaryrefslogtreecommitdiff
path: root/xfa/fgas
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-25 11:23:43 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-25 11:23:43 -0700
commitb6853cfe4fd1ee089dfdd0cb09bbc4063532ef82 (patch)
tree1404031e845c8b4b09d5a68fd81f09a7d2865d59 /xfa/fgas
parent2a8a20cde4c8e2294f6868bb097fe450960a709f (diff)
downloadpdfium-b6853cfe4fd1ee089dfdd0cb09bbc4063532ef82.tar.xz
Pass CFX_*StringCs to FX_HashCode_GETA and _GETW hash functions.
Too many calls were of the form fn(x.c_str(), x.GetLength()) which is an anti-pattern given the StringC classes which tie these together. There are a few places where explicit CFX_*StringCs are constructed, but this can be avoided by changing the args to these functions in the same manner. Removed String_ from name of functions since it added little value. Also removed default argument. Review URL: https://codereview.chromium.org/1919563002
Diffstat (limited to 'xfa/fgas')
-rw-r--r--xfa/fgas/crt/fgas_codepage.cpp6
-rw-r--r--xfa/fgas/font/fgas_fontutils.cpp2
-rw-r--r--xfa/fgas/font/fgas_stdfontmgr.cpp19
-rw-r--r--xfa/fgas/localization/fgas_locale.cpp11
4 files changed, 18 insertions, 20 deletions
diff --git a/xfa/fgas/crt/fgas_codepage.cpp b/xfa/fgas/crt/fgas_codepage.cpp
index 4734a0005e..36c40a6469 100644
--- a/xfa/fgas/crt/fgas_codepage.cpp
+++ b/xfa/fgas/crt/fgas_codepage.cpp
@@ -309,12 +309,12 @@ uint16_t FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) {
if (iLength == 0) {
return 0xFFFF;
}
- uint32_t uHash = FX_HashCode_String_GetA(pStr, iLength, TRUE);
- int32_t iStart = 0, iMid;
+ uint32_t uHash = FX_HashCode_GetA(CFX_ByteStringC(pStr, iLength), true);
+ int32_t iStart = 0;
int32_t iEnd = sizeof(g_FXCPHashTable) / sizeof(FX_STR2CPHASH) - 1;
FXSYS_assert(iEnd >= 0);
do {
- iMid = (iStart + iEnd) / 2;
+ int32_t iMid = (iStart + iEnd) / 2;
const FX_STR2CPHASH& cp = g_FXCPHashTable[iMid];
if (uHash == cp.uHash) {
return (uint16_t)cp.uCodePage;
diff --git a/xfa/fgas/font/fgas_fontutils.cpp b/xfa/fgas/font/fgas_fontutils.cpp
index 12271fbb64..21d5d0b5a5 100644
--- a/xfa/fgas/font/fgas_fontutils.cpp
+++ b/xfa/fgas/font/fgas_fontutils.cpp
@@ -42,7 +42,7 @@ uint32_t FGAS_GetFontFamilyHash(const FX_WCHAR* pszFontFamily,
wsFont += L"Italic";
}
wsFont += wCodePage;
- return FX_HashCode_String_GetW(wsFont.c_str(), wsFont.GetLength());
+ return FX_HashCode_GetW(wsFont.AsStringC(), false);
}
static const FGAS_FONTUSB g_FXGdiFontUSBTable[] = {
{0x0000, 0x007F, 0, 1252}, {0x0080, 0x00FF, 1, 1252},
diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp
index 9e8c824118..4b2a1422d2 100644
--- a/xfa/fgas/font/fgas_stdfontmgr.cpp
+++ b/xfa/fgas/font/fgas_stdfontmgr.cpp
@@ -176,7 +176,7 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, int32_t iLength) {
}
IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) {
FXSYS_assert(pszFileName != NULL);
- uint32_t dwHash = FX_HashCode_String_GetW(pszFileName, -1);
+ uint32_t dwHash = FX_HashCode_GetW(pszFileName, false);
IFX_Font* pFont = NULL;
if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
if (pFont != NULL) {
@@ -230,8 +230,8 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont,
}
void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles,
(void*)(uintptr_t)wCodePage};
- uint32_t dwHash =
- FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*));
+ uint32_t dwHash = FX_HashCode_GetA(
+ CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false);
IFX_Font* pFont = NULL;
if (m_DeriveFonts.GetCount() > 0) {
m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont);
@@ -702,8 +702,7 @@ IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage,
CFX_ByteString bsHash;
bsHash.Format("%d, %d", wCodePage, dwFontStyles);
bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
- uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength());
-
+ uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr;
if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
if (!pFonts)
@@ -759,7 +758,7 @@ IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode,
else
bsHash.Format("%d, %d", wCodePage, dwFontStyles);
bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
- uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength());
+ uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr;
if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
if (!pFonts)
@@ -847,7 +846,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer,
int32_t* pFaceCount) {
void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength};
uint32_t dwHash =
- FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*));
+ FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false);
IFX_FileAccess* pFontAccess = nullptr;
m_Hash2FileAccess.Lookup(dwHash, pFontAccess);
return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
@@ -860,7 +859,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName,
CFX_ByteString bsHash;
bsHash += CFX_WideString(pszFileName).UTF8Encode();
- uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength());
+ uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
IFX_FileAccess* pFontAccess = nullptr;
if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) {
pFontAccess = FX_CreateDefaultFileAccess(pszFileName);
@@ -877,7 +876,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream,
FX_BOOL bSaveStream) {
void* Hash[1] = {(void*)(uintptr_t)pFontStream};
uint32_t dwHash =
- FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*));
+ FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false);
IFX_FileAccess* pFontAccess = nullptr;
m_Hash2FileAccess.Lookup(dwHash, pFontAccess);
@@ -894,7 +893,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess,
if (bWantCache) {
CFX_ByteString bsHash;
bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex);
- dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength());
+ dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) {
if (pFont) {
if (pFaceCount)
diff --git a/xfa/fgas/localization/fgas_locale.cpp b/xfa/fgas/localization/fgas_locale.cpp
index 6e0add1fa5..9a8e05cbc7 100644
--- a/xfa/fgas/localization/fgas_locale.cpp
+++ b/xfa/fgas/localization/fgas_locale.cpp
@@ -595,8 +595,7 @@ FX_LOCALECATEGORY CFX_FormatString::GetCategory(
wsCategory += pStr[ccf];
ccf++;
}
- uint32_t dwHash =
- FX_HashCode_String_GetW(wsCategory.c_str(), wsCategory.GetLength());
+ uint32_t dwHash = FX_HashCode_GetW(wsCategory.AsStringC(), false);
if (dwHash == FX_LOCALECATEGORY_DateHash) {
if (eCategory == FX_LOCALECATEGORY_Time) {
return FX_LOCALECATEGORY_DateTime;
@@ -755,8 +754,8 @@ IFX_Locale* CFX_FormatString::GetNumericFormat(const CFX_WideString& wsPattern,
while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') {
wsSubCategory += pStr[ccf++];
}
- uint32_t dwSubHash = FX_HashCode_String_GetW(
- wsSubCategory.c_str(), wsSubCategory.GetLength());
+ uint32_t dwSubHash =
+ FX_HashCode_GetW(wsSubCategory.AsStringC(), false);
FX_LOCALENUMSUBCATEGORY eSubCategory = FX_LOCALENUMPATTERN_Decimal;
for (int32_t i = 0; i < g_iFXLocaleNumSubCatCount; i++) {
if (g_FXLocaleNumSubCatData[i].uHash == dwSubHash) {
@@ -2209,8 +2208,8 @@ FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat(
while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') {
wsSubCategory += pStr[ccf++];
}
- uint32_t dwSubHash = FX_HashCode_String_GetW(
- wsSubCategory.c_str(), wsSubCategory.GetLength());
+ uint32_t dwSubHash =
+ FX_HashCode_GetW(wsSubCategory.AsStringC(), false);
FX_LOCALEDATETIMESUBCATEGORY eSubCategory =
FX_LOCALEDATETIMESUBCATEGORY_Medium;
for (int32_t i = 0; i < g_iFXLocaleDateTimeSubCatCount; i++) {