summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-07-04 12:02:45 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-04 20:42:11 +0000
commitea7555ae8cae2f50dfb2322d5c19384f43212bd5 (patch)
treeeeec552b39a0b8b8c389381b6fa7745ad8f96660 /xfa/fxfa
parentcb50b5fd0d52bc5766da4173f385dac52cf0b8be (diff)
downloadpdfium-ea7555ae8cae2f50dfb2322d5c19384f43212bd5.tar.xz
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 <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmlexer.cpp25
1 files 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 <algorithm>
+
#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;
}