diff options
author | Lei Zhang <thestig@chromium.org> | 2016-02-25 14:35:23 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-02-25 14:35:23 -0800 |
commit | f8e21f34e9b67c5b9e754e949c58a5113ea4d746 (patch) | |
tree | d6d2c774ae099320c41fab43cfa4857f1274aa25 /xfa/src/fgas | |
parent | 198362223d2257ded96895bd91df2bea422f361e (diff) | |
download | pdfium-f8e21f34e9b67c5b9e754e949c58a5113ea4d746.tar.xz |
Use std::lower_bound() in a couple places.
Do some cleanups along the way.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1732223002 .
Diffstat (limited to 'xfa/src/fgas')
-rw-r--r-- | xfa/src/fgas/src/localization/fx_locale.cpp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/xfa/src/fgas/src/localization/fx_locale.cpp b/xfa/src/fgas/src/localization/fx_locale.cpp index 46eeae0c4f..ca12dbb69e 100644 --- a/xfa/src/fgas/src/localization/fx_locale.cpp +++ b/xfa/src/fgas/src/localization/fx_locale.cpp @@ -55,8 +55,6 @@ static const FX_LOCALETIMEZONEINFO g_FXLocaleTimeZoneData[] = { {FXBSTR_ID(0, 'M', 'D', 'T'), -6, 0}, {FXBSTR_ID(0, 'M', 'S', 'T'), -7, 0}, {FXBSTR_ID(0, 'P', 'D', 'T'), -7, 0}, {FXBSTR_ID(0, 'P', 'S', 'T'), -8, 0}, }; -static const int32_t g_iFXLocaleTimeZoneCount = - sizeof(g_FXLocaleTimeZoneData) / sizeof(FX_LOCALETIMEZONEINFO); static const CFX_WideStringC gs_wsTextSymbols = FX_WSTRC(L"AXO09"); static const CFX_WideStringC gs_wsTimeSymbols = FX_WSTRC(L"hHkKMSFAzZ"); @@ -2771,22 +2769,13 @@ static FX_BOOL FX_ParseLocaleTime(const CFX_WideString& wsTime, } FX_ResolveZone(hour, minute, tzDiff, pLocale); } else { - const FX_LOCALETIMEZONEINFO* pTimeZoneInfo = NULL; - int32_t iStart = 0; - int32_t iEnd = g_iFXLocaleTimeZoneCount - 1; - do { - int32_t iMid = (iStart + iEnd) / 2; - const FX_LOCALETIMEZONEINFO* pInfo = g_FXLocaleTimeZoneData + iMid; - if (dwHash == pInfo->uHash) { - pTimeZoneInfo = pInfo; - break; - } else if (dwHash < pInfo->uHash) { - iEnd = iMid - 1; - } else { - iStart = iMid + 1; - } - } while (iStart <= iEnd); - if (pTimeZoneInfo) { + const FX_LOCALETIMEZONEINFO* pEnd = + g_FXLocaleTimeZoneData + FX_ArraySize(g_FXLocaleTimeZoneData); + const FX_LOCALETIMEZONEINFO* pTimeZoneInfo = + std::lower_bound(g_FXLocaleTimeZoneData, pEnd, dwHash, + [](const FX_LOCALETIMEZONEINFO& info, + FX_DWORD hash) { return info.uHash < hash; }); + if (pTimeZoneInfo < pEnd && dwHash == pTimeZoneInfo->uHash) { hour += pTimeZoneInfo->iHour; minute += pTimeZoneInfo->iHour > 0 ? pTimeZoneInfo->iMinute : -pTimeZoneInfo->iMinute; |