From e86db739729993db51090ce6e2b676e6a81ab1a5 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 31 Jan 2018 17:14:22 +0000 Subject: Remove handrolled search from GetEventParaInfoByName BUG=pdfium:798 Change-Id: If6219f06303c78ecc8ddda52dd0095d658148e91 Reviewed-on: https://pdfium-review.googlesource.com/24718 Commit-Queue: Ryan Harrison Reviewed-by: dsinclair --- fxjs/xfa/cjx_node.cpp | 24 +++++++++++------------- 1 file 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; } -- cgit v1.2.3