@@ -1239,9 +1239,9 @@ uint8_t* ExtensionSet::_InternalSerializeImpl(
1239
1239
return target;
1240
1240
}
1241
1241
const KeyValue* end = flat_end ();
1242
- for ( const KeyValue* it = std::lower_bound (
1243
- flat_begin (), end, start_field_number, KeyValue::FirstComparator ()) ;
1244
- it != end && it->first < end_field_number; ++it) {
1242
+ const KeyValue* it = flat_begin ();
1243
+ while (it != end && it-> first < start_field_number) ++it ;
1244
+ for (; it != end && it->first < end_field_number; ++it) {
1245
1245
target = it->second .InternalSerializeFieldWithCachedSizesToArray (
1246
1246
extendee, this , it->first , target, stream);
1247
1247
}
@@ -1566,9 +1566,11 @@ const ExtensionSet::Extension* ExtensionSet::FindOrNull(int key) const {
1566
1566
if (flat_size_ == 0 ) {
1567
1567
return nullptr ;
1568
1568
} else if (PROTOBUF_PREDICT_TRUE (!is_large ())) {
1569
- auto it = std::lower_bound (flat_begin (), flat_end () - 1 , key,
1570
- KeyValue::FirstComparator ());
1571
- return it->first == key ? &it->second : nullptr ;
1569
+ for (auto it = flat_begin (), end = flat_end ();
1570
+ it != end && it->first <= key; ++it) {
1571
+ if (it->first == key) return &it->second ;
1572
+ }
1573
+ return nullptr ;
1572
1574
} else {
1573
1575
return FindOrNullInLargeMap (key);
1574
1576
}
@@ -1601,10 +1603,9 @@ std::pair<ExtensionSet::Extension*, bool> ExtensionSet::Insert(int key) {
1601
1603
return {&maybe.first ->second , maybe.second };
1602
1604
}
1603
1605
KeyValue* end = flat_end ();
1604
- KeyValue* it =
1605
- std::lower_bound (flat_begin (), end, key, KeyValue::FirstComparator ());
1606
- if (it != end && it->first == key) {
1607
- return {&it->second , false };
1606
+ KeyValue* it = flat_begin ();
1607
+ for (; it != end && it->first <= key; ++it) {
1608
+ if (it->first == key) return {&it->second , false };
1608
1609
}
1609
1610
if (flat_size_ < flat_capacity_) {
1610
1611
std::copy_backward (it, end, end + 1 );
@@ -1681,11 +1682,12 @@ void ExtensionSet::Erase(int key) {
1681
1682
return ;
1682
1683
}
1683
1684
KeyValue* end = flat_end ();
1684
- KeyValue* it =
1685
- std::lower_bound (flat_begin (), end, key, KeyValue::FirstComparator ());
1686
- if (it != end && it->first == key) {
1687
- std::copy (it + 1 , end, it);
1688
- --flat_size_;
1685
+ for (KeyValue* it = flat_begin (); it != end && it->first <= key; ++it) {
1686
+ if (it->first == key) {
1687
+ std::copy (it + 1 , end, it);
1688
+ --flat_size_;
1689
+ return ;
1690
+ }
1689
1691
}
1690
1692
}
1691
1693
0 commit comments