From dfcb8af6f7c67f1bb2e349baada6afd2f54a2340 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 30 Jun 2017 11:38:03 -0400 Subject: Remove hand rolled bsearch from HTMLCode2STR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=pdfium:786 Change-Id: I84f4012b5225f81df604fcc6e0836ac5d19f1414 Reviewed-on: https://pdfium-review.googlesource.com/7153 Reviewed-by: Nicolás Peña Reviewed-by: Lei Zhang Commit-Queue: Ryan Harrison --- xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp | 28 +++++++++++----------------- xfa/fxfa/fm2js/cxfa_fm2jscontext.h | 2 +- 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); -- cgit v1.2.3