From b6853cfe4fd1ee089dfdd0cb09bbc4063532ef82 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 25 Apr 2016 11:23:43 -0700 Subject: 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 --- xfa/fxfa/parser/xfa_basic_imp.cpp | 71 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'xfa/fxfa/parser/xfa_basic_imp.cpp') diff --git a/xfa/fxfa/parser/xfa_basic_imp.cpp b/xfa/fxfa/parser/xfa_basic_imp.cpp index 631b7c10ca..728ecfc319 100644 --- a/xfa/fxfa/parser/xfa_basic_imp.cpp +++ b/xfa/fxfa/parser/xfa_basic_imp.cpp @@ -21,12 +21,12 @@ #include "xfa/fxfa/parser/xfa_utils.h" const XFA_PACKETINFO* XFA_GetPacketByName(const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAPacketCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid; @@ -63,12 +63,12 @@ const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) { const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAEnumCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAEnumCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid; @@ -87,12 +87,12 @@ const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { } const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAAttributeCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAAttributeCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid; @@ -104,7 +104,7 @@ const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { iStart = iMid + 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; @@ -177,12 +177,12 @@ CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_ELEMENT eElement, } const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAElementCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAElementCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; @@ -334,10 +334,9 @@ const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_ELEMENT eElement, const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, const CFX_WideStringC& wsMethodName) { - int32_t iLength = wsMethodName.GetLength(); - if (iLength == 0) { - return NULL; - } + if (wsMethodName.IsEmpty()) + return nullptr; + int32_t iElementIndex = eElement; while (iElementIndex != -1) { const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; @@ -346,8 +345,9 @@ const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, iElementIndex = scriptIndex->wParentIndex; continue; } - uint32_t uHash = FX_HashCode_String_GetW(wsMethodName.c_str(), iLength); - int32_t iStart = scriptIndex->wMethodStart, iEnd = iStart + icount - 1; + uint32_t uHash = FX_HashCode_GetW(wsMethodName, false); + int32_t iStart = scriptIndex->wMethodStart; + int32_t iEnd = iStart + icount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; @@ -366,10 +366,9 @@ const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( XFA_ELEMENT eElement, const CFX_WideStringC& wsAttributeName) { - int32_t iLength = wsAttributeName.GetLength(); - if (iLength == 0) { - return NULL; - } + if (wsAttributeName.IsEmpty()) + return nullptr; + int32_t iElementIndex = eElement; while (iElementIndex != -1) { const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; @@ -378,7 +377,7 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( iElementIndex = scriptIndex->wParentIndex; continue; } - uint32_t uHash = FX_HashCode_String_GetW(wsAttributeName.c_str(), iLength); + uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; do { int32_t iMid = (iStart + iEnd) / 2; -- cgit v1.2.3