@@ -1239,9 +1239,9 @@ uint8_t* ExtensionSet::_InternalSerializeImpl(
12391239 return target;
12401240 }
12411241 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) {
12451245 target = it->second .InternalSerializeFieldWithCachedSizesToArray (
12461246 extendee, this , it->first , target, stream);
12471247 }
@@ -1566,9 +1566,11 @@ const ExtensionSet::Extension* ExtensionSet::FindOrNull(int key) const {
15661566 if (flat_size_ == 0 ) {
15671567 return nullptr ;
15681568 } 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 ;
15721574 } else {
15731575 return FindOrNullInLargeMap (key);
15741576 }
@@ -1601,10 +1603,9 @@ std::pair<ExtensionSet::Extension*, bool> ExtensionSet::Insert(int key) {
16011603 return {&maybe.first ->second , maybe.second };
16021604 }
16031605 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 };
16081609 }
16091610 if (flat_size_ < flat_capacity_) {
16101611 std::copy_backward (it, end, end + 1 );
@@ -1681,11 +1682,12 @@ void ExtensionSet::Erase(int key) {
16811682 return ;
16821683 }
16831684 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+ }
16891691 }
16901692}
16911693
0 commit comments