From a975a83691dbfdf34754c7705dcc715bc5c73820 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 31 Jan 2018 20:16:04 +0000 Subject: Remove handrolled bsearch from XFA_GetScriptAttributeByName BUG=pdfium:798 Change-Id: Ie680eff06fdee49d843e0cb847ee9c919975cfb5 Reviewed-on: https://pdfium-review.googlesource.com/24779 Reviewed-by: dsinclair Commit-Queue: Ryan Harrison --- xfa/fxfa/parser/xfa_utils.cpp | 22 ++++++++++------------ xfa/fxfa/parser/xfa_utils.h | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index 785119b62e..f0d2afdbcc 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp @@ -579,30 +579,28 @@ int32_t XFA_MapRotation(int32_t nRotation) { const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( XFA_Element eElement, - const WideStringView& wsAttributeName) { + WideStringView wsAttributeName) { if (wsAttributeName.IsEmpty()) return nullptr; int32_t iElementIndex = static_cast(eElement); while (iElementIndex != -1) { const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; - int32_t icount = scriptIndex->wAttributeCount; - if (icount == 0) { + size_t iCount = scriptIndex->wAttributeCount; + if (iCount == 0) { iElementIndex = scriptIndex->wParentIndex; continue; } + uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); - int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; - do { - int32_t iMid = (iStart + iEnd) / 2; - const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iMid; + size_t iStart = scriptIndex->wAttributeStart; + size_t iEnd = iStart + iCount; + for (size_t iter = iStart; iter < iEnd; ++iter) { + const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iter; if (uHash == pInfo->uHash) return pInfo; - if (uHash < pInfo->uHash) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + } + iElementIndex = scriptIndex->wParentIndex; } return nullptr; diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 2dfdb1a381..3b59ac8b3a 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -37,6 +37,6 @@ void XFA_DataExporter_RegenerateFormFile( const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( XFA_Element eElement, - const WideStringView& wsAttributeName); + WideStringView wsAttributeName); #endif // XFA_FXFA_PARSER_XFA_UTILS_H_ -- cgit v1.2.3