summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-06-30 11:38:03 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-30 18:11:25 +0000
commitdfcb8af6f7c67f1bb2e349baada6afd2f54a2340 (patch)
tree9e7d84a1195ac8d49c605fc827f02f154c588817 /xfa
parenta173900b19e158130df049dd1c31b7494baefffd (diff)
downloadpdfium-dfcb8af6f7c67f1bb2e349baada6afd2f54a2340.tar.xz
Remove hand rolled bsearch from HTMLCode2STR
BUG=pdfium:786 Change-Id: I84f4012b5225f81df604fcc6e0836ac5d19f1414 Reviewed-on: https://pdfium-review.googlesource.com/7153 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp28
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.h2
2 files changed, 12 insertions, 18 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 0b8ea19ea5..94e3fb10cd 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -3579,7 +3579,7 @@ void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString,
while (i < iLen) {
uint32_t ch = pData[i];
CFX_WideString htmlReserve;
- if (HTMLCode2STR(ch, htmlReserve)) {
+ if (HTMLCode2STR(ch, &htmlReserve)) {
wsResultBuf.AppendChar(L'&');
wsResultBuf << htmlReserve;
wsResultBuf.AppendChar(L';');
@@ -3701,22 +3701,16 @@ bool CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData,
// static
bool CXFA_FM2JSContext::HTMLCode2STR(uint32_t iCode,
- CFX_WideString& wsHTMLReserve) {
- int32_t iStart = 0;
- int32_t iEnd = FX_ArraySize(reservesForEncode) - 1;
- do {
- int32_t iMid = (iStart + iEnd) / 2;
- XFA_FMHtmlReserveCode htmlreservecode = reservesForEncode[iMid];
- if (iCode == htmlreservecode.m_uCode) {
- wsHTMLReserve = htmlreservecode.m_htmlReserve;
- return true;
- }
-
- if (iCode < htmlreservecode.m_uCode)
- iEnd = iMid - 1;
- else
- iStart = iMid + 1;
- } while (iStart <= iEnd);
+ CFX_WideString* wsHTMLReserve) {
+ const XFA_FMHtmlReserveCode* result = std::lower_bound(
+ std::begin(reservesForEncode), std::end(reservesForEncode), iCode,
+ [](const XFA_FMHtmlReserveCode iter, const uint32_t& val) {
+ return iter.m_uCode < val;
+ });
+ if (result != std::end(reservesForEncode) && result->m_uCode == iCode) {
+ *wsHTMLReserve = result->m_htmlReserve;
+ return true;
+ }
return false;
}
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.h b/xfa/fxfa/fm2js/cxfa_fm2jscontext.h
index 63fc0f42bd..a5769a36cc 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.h
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.h
@@ -240,7 +240,7 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject {
static void EncodeXML(const CFX_ByteStringC& szXMLString,
CFX_ByteTextBuf& szResultBuf);
static bool HTMLSTR2Code(const CFX_WideStringC& pData, uint32_t& iCode);
- static bool HTMLCode2STR(uint32_t iCode, CFX_WideString& wsHTMLReserve);
+ static bool HTMLCode2STR(uint32_t iCode, CFX_WideString* wsHTMLReserve);
static void Format(CFXJSE_Value* pThis,
const CFX_ByteStringC& szFuncName,
CFXJSE_Arguments& args);