Use default/projection forms of C++20 std::ranges::lower_bound() -- same with upper_bound. Change-Id: I60728a199f498649828c0ca9692dd79512dc3382 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/133470 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index c9cebe0..4b0bd77 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -227,9 +227,7 @@ continue; } new_obj_num_array_.insert( - std::lower_bound(new_obj_num_array_.begin(), new_obj_num_array_.end(), - objnum), - objnum); + std::ranges::lower_bound(new_obj_num_array_, objnum), objnum); } }
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 3d6a34e..f7f9619 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -8,6 +8,7 @@ #include <algorithm> #include <array> +#include <functional> #include <limits> #include <utility> #include <vector> @@ -900,12 +901,10 @@ if (charset_ != CIDSET_JAPAN1 || font_file_) { return nullptr; } + const auto* pTransform = std::ranges::lower_bound( + kJapan1VerticalCIDs, cid, std::less<>{}, &CIDTransform::cid); - const auto* pBegin = std::begin(kJapan1VerticalCIDs); - const auto* pEnd = std::end(kJapan1VerticalCIDs); - const auto* pTransform = std::lower_bound( - pBegin, pEnd, cid, - [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); - - return pTransform < pEnd && cid == pTransform->cid ? pTransform : nullptr; + return pTransform != std::end(kJapan1VerticalCIDs) && cid == pTransform->cid + ? pTransform + : nullptr; }
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp index c0c8e37..f43c072 100644 --- a/core/fpdfapi/font/cpdf_cmap.cpp +++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -7,6 +7,7 @@ #include "core/fpdfapi/font/cpdf_cmap.h" #include <array> +#include <functional> #include <utility> #include <vector> @@ -304,11 +305,9 @@ if (coding_ == CIDCoding::kCID) { return static_cast<uint16_t>(charcode); } - if (embed_map_) { return fxcmap::CIDFromCharCode(embed_map_, charcode); } - if (direct_charcode_to_cidtable_.empty()) { return static_cast<uint16_t>(charcode); } @@ -319,11 +318,9 @@ } auto it = - std::lower_bound(additional_charcode_to_cidmappings_.begin(), - additional_charcode_to_cidmappings_.end(), charcode, - [](const CPDF_CMap::CIDRange& arg, uint32_t val) { - return arg.end_code_ < val; - }); + std::ranges::lower_bound(additional_charcode_to_cidmappings_, charcode, + std::less<>{}, &CPDF_CMap::CIDRange::end_code_); + if (it == additional_charcode_to_cidmappings_.end() || it->start_code_ > charcode) { return 0;
diff --git a/core/fpdfapi/page/cpdf_psengine.cpp b/core/fpdfapi/page/cpdf_psengine.cpp index 2f53f15..1564518 100644 --- a/core/fpdfapi/page/cpdf_psengine.cpp +++ b/core/fpdfapi/page/cpdf_psengine.cpp
@@ -9,6 +9,7 @@ #include <math.h> #include <algorithm> +#include <functional> #include <limits> #include <utility> @@ -186,11 +187,8 @@ } void CPDF_PSProc::AddOperator(ByteStringView word) { - const auto* pFound = - std::lower_bound(std::begin(kPsOpNames), std::end(kPsOpNames), word, - [](const PDF_PSOpName& name, ByteStringView word) { - return name.name < word; - }); + const auto* pFound = std::ranges::lower_bound(kPsOpNames, word, std::less<>{}, + &PDF_PSOpName::name); if (pFound != std::end(kPsOpNames) && pFound->name == word) { operators_.push_back(std::make_unique<CPDF_PSOP>(pFound->op)); } else {
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 692eac5..d4660cc 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -1372,9 +1372,8 @@ } int32_t CPDF_StreamContentParser::GetCurrentStreamIndex() { - auto it = std::upper_bound(stream_start_offsets_.begin(), - stream_start_offsets_.end(), - syntax_->GetPos() + start_parse_offset_); + auto it = std::ranges::upper_bound(stream_start_offsets_, + syntax_->GetPos() + start_parse_offset_); return (it - stream_start_offsets_.begin()) - 1; }
diff --git a/core/fxcrt/css/cfx_cssdata.cpp b/core/fxcrt/css/cfx_cssdata.cpp index 3225615..d9c5283 100644 --- a/core/fxcrt/css/cfx_cssdata.cpp +++ b/core/fxcrt/css/cfx_cssdata.cpp
@@ -7,6 +7,7 @@ #include "core/fxcrt/css/cfx_cssdata.h" #include <algorithm> +#include <functional> #include <utility> #include "core/fxcrt/check_op.h" @@ -62,11 +63,8 @@ } uint32_t hash = FX_HashCode_GetLoweredW(name); - auto* result = std::lower_bound( - std::begin(kPropertyTable), std::end(kPropertyTable), hash, - [](const CFX_CSSData::Property& iter, const uint32_t& hash) { - return iter.dwHash < hash; - }); + auto* result = std::ranges::lower_bound(kPropertyTable, hash, std::less<>{}, + &CFX_CSSData::Property::dwHash); if (result != std::end(kPropertyTable) && result->dwHash == hash) { return result; @@ -89,11 +87,9 @@ } uint32_t hash = FX_HashCode_GetLoweredW(wsName); - auto* result = std::lower_bound( - std::begin(kPropertyValueTable), std::end(kPropertyValueTable), hash, - [](const PropertyValue& iter, const uint32_t& hash) { - return iter.dwHash < hash; - }); + auto* result = + std::ranges::lower_bound(kPropertyValueTable, hash, std::less<>{}, + &CFX_CSSData::PropertyValue::dwHash); if (result != std::end(kPropertyValueTable) && result->dwHash == hash) { return result;
diff --git a/core/fxcrt/fx_codepage.cpp b/core/fxcrt/fx_codepage.cpp index e189eaa..2f9bce6 100644 --- a/core/fxcrt/fx_codepage.cpp +++ b/core/fxcrt/fx_codepage.cpp
@@ -7,6 +7,7 @@ #include "core/fxcrt/fx_codepage.h" #include <algorithm> +#include <functional> #include <iterator> #include <utility> @@ -224,11 +225,9 @@ } FX_CodePage FX_GetCodePageFromCharset(FX_Charset charset) { - auto* result = std::lower_bound( - std::begin(kFXCharset2CodePageTable), std::end(kFXCharset2CodePageTable), - charset, [](const FX_CHARSET_MAP& iter, const FX_Charset& charset) { - return iter.charset < charset; - }); + auto* result = + std::ranges::lower_bound(kFXCharset2CodePageTable, charset, std::less<>{}, + &FX_CHARSET_MAP::charset); if (result != std::end(kFXCharset2CodePageTable) && result->charset == charset) { return result->codepage;
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp index 4aff41f..762fada 100644 --- a/core/fxcrt/xml/cfx_xmlparser.cpp +++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -9,6 +9,7 @@ #include <stdint.h> #include <algorithm> +#include <functional> #include <iterator> #include <stack> #include <utility> @@ -57,9 +58,8 @@ // static bool CFX_XMLParser::IsXMLNameChar(wchar_t ch, bool bFirstChar) { - auto* it = std::lower_bound( - std::begin(kXMLNameChars), std::end(kXMLNameChars), ch, - [](const FX_XMLNAMECHAR& arg, wchar_t ch) { return arg.wEnd < ch; }); + auto* it = std::ranges::lower_bound(kXMLNameChars, ch, std::less<>{}, + &FX_XMLNAMECHAR::wEnd); return it != std::end(kXMLNameChars) && ch >= it->wStart && (!bFirstChar || it->bStartChar); }
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index 3d55863..ce21eb9 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -8,6 +8,7 @@ #include <algorithm> #include <array> +#include <functional> #include <iterator> #include <utility> @@ -56,11 +57,9 @@ uint32_t SkiaGetSubstFont(uint32_t hash, pdfium::span<const SkiaFontMap> font_map) { - const SkiaFontMap* it = - std::lower_bound(font_map.begin(), font_map.end(), hash, - [](const SkiaFontMap& item, uint32_t hash) { - return item.family < hash; - }); + const SkiaFontMap* it = std::ranges::lower_bound( + font_map, hash, std::less<>{}, &SkiaFontMap::family); + if (it != font_map.end() && it->family == hash) { return it->subst; }
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index edb2e2d..43d3a6b 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp
@@ -6,6 +6,7 @@ #include "fxjs/xfa/cjx_node.h" +#include <functional> #include <memory> #include <utility> #include <vector> @@ -79,11 +80,8 @@ } uint32_t uHash = FX_HashCode_GetW(wsEventName); - auto* result = std::lower_bound( - std::begin(kExecEventParaInfoTable), std::end(kExecEventParaInfoTable), - uHash, [](const ExecEventParaInfo& iter, const uint32_t& hash) { - return iter.hash_ < hash; - }); + auto* result = std::ranges::lower_bound( + kExecEventParaInfoTable, uHash, std::less<>{}, &ExecEventParaInfo::hash_); if (result != std::end(kExecEventParaInfoTable) && result->hash_ == uHash) { return result; }
diff --git a/xfa/fgas/font/fgas_fontutils.cpp b/xfa/fgas/font/fgas_fontutils.cpp index 3bde817..9d7a314 100644 --- a/xfa/fgas/font/fgas_fontutils.cpp +++ b/xfa/fgas/font/fgas_fontutils.cpp
@@ -6,6 +6,7 @@ #include "xfa/fgas/font/fgas_fontutils.h" +#include <functional> #include <iterator> #include "build/build_config.h" @@ -2451,15 +2452,12 @@ WideString FGAS_FontNameToEnglishName(const WideString& wsLocalName) { uint32_t dwLocalNameHash = FX_HashCode_GetLoweredW(wsLocalName.AsStringView()); - const FGAS_FontInfo* pBegin = std::begin(kXFAFontsMap); - const FGAS_FontInfo* pEnd = std::end(kXFAFontsMap); const FGAS_FontInfo* font_info = - std::lower_bound(pBegin, pEnd, dwLocalNameHash, - [](const FGAS_FontInfo& entry, uint32_t hash) { - return entry.dwFontNameHash < hash; - }); + std::ranges::lower_bound(kXFAFontsMap, dwLocalNameHash, std::less<>{}, + &FGAS_FontInfo::dwFontNameHash); - if (font_info < pEnd && font_info->dwFontNameHash == dwLocalNameHash) { + if (font_info < std::end(kXFAFontsMap) && + font_info->dwFontNameHash == dwLocalNameHash) { return WideString::FromASCII(ByteStringView(font_info->pPsName)); } return wsLocalName; @@ -2470,15 +2468,12 @@ wsFontNameTemp.Remove(L' '); uint32_t dwCurFontNameHash = FX_HashCode_GetLoweredW(wsFontNameTemp.AsStringView()); - const FGAS_FontInfo* pBegin = std::begin(kXFAFontsMap); - const FGAS_FontInfo* pEnd = std::end(kXFAFontsMap); const FGAS_FontInfo* font_info = - std::lower_bound(pBegin, pEnd, dwCurFontNameHash, - [](const FGAS_FontInfo& entry, uint32_t hash) { - return entry.dwFontNameHash < hash; - }); + std::ranges::lower_bound(kXFAFontsMap, dwCurFontNameHash, std::less<>{}, + &FGAS_FontInfo::dwFontNameHash); - if (font_info < pEnd && font_info->dwFontNameHash == dwCurFontNameHash) { + if (font_info < std::end(kXFAFontsMap) && + font_info->dwFontNameHash == dwCurFontNameHash) { return font_info; } return nullptr;
diff --git a/xfa/fgas/layout/cfgas_rtfbreak.cpp b/xfa/fgas/layout/cfgas_rtfbreak.cpp index 4a7f19f..2d3e1da 100644 --- a/xfa/fgas/layout/cfgas_rtfbreak.cpp +++ b/xfa/fgas/layout/cfgas_rtfbreak.cpp
@@ -42,8 +42,7 @@ void CFGAS_RTFBreak::AddPositionedTab(float fTabPos) { int32_t iTabPos = std::min( FXSYS_roundf(fTabPos * kConversionFactor) + line_start_, line_width_); - auto it = std::lower_bound(positioned_tabs_.begin(), positioned_tabs_.end(), - iTabPos); + auto it = std::ranges::lower_bound(positioned_tabs_, iTabPos); if (it != positioned_tabs_.end() && *it == iTabPos) { return; } @@ -61,8 +60,7 @@ } bool CFGAS_RTFBreak::GetPositionedTab(int32_t* iTabPos) const { - auto it = std::upper_bound(positioned_tabs_.begin(), positioned_tabs_.end(), - *iTabPos); + auto it = std::ranges::upper_bound(positioned_tabs_, *iTabPos); if (it == positioned_tabs_.end()) { return false; }
diff --git a/xfa/fxfa/cxfa_ffbarcode.cpp b/xfa/fxfa/cxfa_ffbarcode.cpp index 98a8432..d23de05 100644 --- a/xfa/fxfa/cxfa_ffbarcode.cpp +++ b/xfa/fxfa/cxfa_ffbarcode.cpp
@@ -6,6 +6,7 @@ #include "xfa/fxfa/cxfa_ffbarcode.h" +#include <functional> #include <utility> #include "core/fxcrt/check.h" @@ -117,16 +118,13 @@ if (wsName.IsEmpty()) { return BC_TYPE::kUnknown; } - - auto* it = std::lower_bound( - std::begin(kBarCodeData), std::end(kBarCodeData), - FX_HashCode_GetLoweredW(wsName.AsStringView()), - [](const BarCodeInfo& arg, uint32_t hash) { return arg.uHash < hash; }); + auto* it = std::ranges::lower_bound( + kBarCodeData, FX_HashCode_GetLoweredW(wsName.AsStringView()), + std::less<>{}, &BarCodeInfo::uHash); if (it != std::end(kBarCodeData) && wsName.EqualsASCII(it->pName)) { return it->eBCType; } - return BC_TYPE::kUnknown; }
diff --git a/xfa/fxfa/parser/xfa_basic_data.cpp b/xfa/fxfa/parser/xfa_basic_data.cpp index 1da5399..6aefa15 100644 --- a/xfa/fxfa/parser/xfa_basic_data.cpp +++ b/xfa/fxfa/parser/xfa_basic_data.cpp
@@ -6,6 +6,7 @@ #include "xfa/fxfa/parser/xfa_basic_data.h" +#include <functional> #include <iterator> #include <utility> @@ -184,9 +185,8 @@ std::optional<XFA_PACKETINFO> XFA_GetPacketByName(WideStringView wsName) { uint32_t hash = FX_HashCode_GetW(wsName); - auto* elem = std::lower_bound( - std::begin(kPacketTable), std::end(kPacketTable), hash, - [](const PacketTableRecord& a, uint32_t hash) { return a.hash < hash; }); + auto* elem = std::ranges::lower_bound(kPacketTable, hash, std::less<>{}, + &PacketTableRecord::hash); if (elem != std::end(kPacketTable) && wsName.EqualsASCII(elem->info.name)) { return elem->info; } @@ -199,13 +199,11 @@ XFA_Element XFA_GetElementByName(WideStringView name) { uint32_t hash = FX_HashCode_GetW(name); - auto* elem = std::lower_bound( - std::begin(kElementRecords), std::end(kElementRecords), hash, - [](const ElementRecord& a, uint32_t hash) { return a.hash < hash; }); + auto* elem = std::ranges::lower_bound(kElementRecords, hash, std::less<>{}, + &ElementRecord::hash); if (elem == std::end(kElementRecords)) { return XFA_Element::Unknown; } - size_t index = std::distance(std::begin(kElementRecords), elem); return name.EqualsASCII(kElementNameSpan[index]) ? elem->element : XFA_Element::Unknown; @@ -240,20 +238,15 @@ std::optional<XFA_AttributeValue> XFA_GetAttributeValueByName( WideStringView name) { auto* it = - std::lower_bound(std::begin(kAttributeValueRecords), - std::end(kAttributeValueRecords), FX_HashCode_GetW(name), - [](const AttributeValueRecord& arg, uint32_t hash) { - return arg.uHash < hash; - }); + std::ranges::lower_bound(kAttributeValueRecords, FX_HashCode_GetW(name), + std::less<>{}, &AttributeValueRecord::uHash); if (it == std::end(kAttributeValueRecords)) { return std::nullopt; } - size_t index = std::distance(std::begin(kAttributeValueRecords), it); if (!name.EqualsASCII(kAttributeValueNameSpan[index])) { return std::nullopt; } - return it->eName; }