summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-31 17:33:02 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-31 17:33:02 +0000
commitab762d33d6c1605a24a6304f31179d5c5059cd34 (patch)
tree40a9f88b78bca83ec4fe9a9e3d368ae61385e7c3 /xfa
parente86db739729993db51090ce6e2b676e6a81ab1a5 (diff)
downloadpdfium-ab762d33d6c1605a24a6304f31179d5c5059cd34.tar.xz
Remove handrolled search from GetCodePageFromCharset
BUG=pdfium:798 Change-Id: If89c162f8a6c15a8a0f4313fbf4713ee2fde5357 Reviewed-on: https://pdfium-review.googlesource.com/24719 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp24
1 files 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;
}