diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-01-31 17:14:22 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-31 17:14:22 +0000 |
commit | e86db739729993db51090ce6e2b676e6a81ab1a5 (patch) | |
tree | 3828fd838b357b61490920ce2798d6a5e9acb44f /fxjs | |
parent | 6ec5ab029194f350866211eccb7ee2a2a0d35bef (diff) | |
download | pdfium-e86db739729993db51090ce6e2b676e6a81ab1a5.tar.xz |
Remove handrolled search from GetEventParaInfoByName
BUG=pdfium:798
Change-Id: If6219f06303c78ecc8ddda52dd0095d658148e91
Reviewed-on: https://pdfium-review.googlesource.com/24718
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 0508651932..8c49b6f1e4 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -65,20 +65,18 @@ const XFA_ExecEventParaInfo gs_eventParaInfos[] = { }; const XFA_ExecEventParaInfo* GetEventParaInfoByName( - const WideStringView& wsEventName) { + WideStringView wsEventName) { + if (wsEventName.IsEmpty()) + return nullptr; + uint32_t uHash = FX_HashCode_GetW(wsEventName, false); - int32_t iStart = 0; - int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; - do { - int32_t iMid = (iStart + iEnd) / 2; - const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; - if (uHash == eventParaInfo->m_uHash) - return eventParaInfo; - if (uHash < eventParaInfo->m_uHash) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + auto* result = std::lower_bound( + std::begin(gs_eventParaInfos), std::end(gs_eventParaInfos), uHash, + [](const XFA_ExecEventParaInfo& iter, const uint16_t& hash) { + return iter.m_uHash < hash; + }); + if (result != std::end(gs_eventParaInfos) && result->m_uHash == uHash) + return result; return nullptr; } |