From ab762d33d6c1605a24a6304f31179d5c5059cd34 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 31 Jan 2018 17:33:02 +0000 Subject: Remove handrolled search from GetCodePageFromCharset BUG=pdfium:798 Change-Id: If89c162f8a6c15a8a0f4313fbf4713ee2fde5357 Reviewed-on: https://pdfium-review.googlesource.com/24719 Commit-Queue: Ryan Harrison Reviewed-by: dsinclair --- xfa/fgas/font/cfgas_fontmgr.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 862e9299b5..1731079bdd 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -67,20 +67,16 @@ const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { }; uint16_t GetCodePageFromCharset(uint8_t charset) { - int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1; - ASSERT(iEnd >= 0); - - int32_t iStart = 0, iMid; - do { - iMid = (iStart + iEnd) / 2; - const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid]; - if (charset == cp.charset) - return cp.codepage; - if (charset < cp.charset) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + auto* result = + std::lower_bound(std::begin(g_FXCharset2CodePageTable), + std::end(g_FXCharset2CodePageTable), charset, + [](const FX_CHARSET_MAP& iter, const uint16_t& charset) { + return iter.charset < charset; + }); + if (result != std::end(g_FXCharset2CodePageTable) && + result->charset == charset) { + return result->codepage; + } return 0xFFFF; } -- cgit v1.2.3