From ea7555ae8cae2f50dfb2322d5c19384f43212bd5 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Tue, 4 Jul 2017 12:02:45 -0400 Subject: Removed hand rolled bsearch from IsKeyword method BUG=pdfium:786 Change-Id: I7a852566cdde301ee896c12d9d29043047c31ad4 Reviewed-on: https://pdfium-review.googlesource.com/7211 Commit-Queue: Ryan Harrison Reviewed-by: dsinclair --- xfa/fxfa/fm2js/cxfa_fmlexer.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp index 433839a88c..7537041bb7 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp @@ -6,6 +6,8 @@ #include "xfa/fxfa/fm2js/cxfa_fmlexer.h" +#include + #include "core/fxcrt/fx_extension.h" #include "third_party/base/ptr_util.h" @@ -472,18 +474,15 @@ const wchar_t* CXFA_FMLexer::Comment(const wchar_t* p) { } XFA_FM_TOKEN CXFA_FMLexer::IsKeyword(const CFX_WideStringC& str) { - uint32_t uHash = FX_HashCode_GetW(str, true); - int32_t iStart = KEYWORD_START; - int32_t iEnd = KEYWORD_END; - do { - int32_t iMid = (iStart + iEnd) / 2; - XFA_FMKeyword keyword = keyWords[iMid]; - if (uHash == keyword.m_uHash) - return keyword.m_type; - if (uHash < keyword.m_uHash) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + uint32_t key = FX_HashCode_GetW(str, true); + auto cmpFunc = [](const XFA_FMKeyword& iter, const uint32_t& val) { + return iter.m_uHash < val; + }; + + const XFA_FMKeyword* result = std::lower_bound( + std::begin(keyWords) + KEYWORD_START, std::end(keyWords), key, cmpFunc); + if (result <= keyWords + KEYWORD_END && result->m_uHash == key) { + return result->m_type; + } return TOKidentifier; } -- cgit v1.2.3