Skip to content

Commit 8c7b1ec

Browse files
Replace FindHelper() with BucketNumber() when only the bucket number is required.
PiperOrigin-RevId: 641931119
1 parent 1aae785 commit 8c7b1ec

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/google/protobuf/map.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,13 +972,13 @@ class KeyMapBase : public UntypedMapBase {
972972
KeyNode* InsertOrReplaceNode(KeyNode* node) {
973973
KeyNode* to_erase = nullptr;
974974
auto p = this->FindHelper(node->key());
975+
map_index_t b = p.bucket;
975976
if (p.node != nullptr) {
976977
erase_no_destroy(p.bucket, static_cast<KeyNode*>(p.node));
977978
to_erase = static_cast<KeyNode*>(p.node);
978979
} else if (ResizeIfLoadIsOutOfRange(num_elements_ + 1)) {
979-
p = FindHelper(node->key());
980+
b = BucketNumber(node->key()); // bucket_number
980981
}
981-
const map_index_t b = p.bucket; // bucket number
982982
InsertUnique(b, node);
983983
++num_elements_;
984984
return to_erase;
@@ -1617,15 +1617,15 @@ class Map : private internal::KeyMapBase<internal::KeyForBase<Key>> {
16171617
template <typename K, typename... Args>
16181618
std::pair<iterator, bool> TryEmplaceInternal(K&& k, Args&&... args) {
16191619
auto p = this->FindHelper(TS::ToView(k));
1620+
internal::map_index_t b = p.bucket;
16201621
// Case 1: key was already present.
16211622
if (p.node != nullptr)
16221623
return std::make_pair(
16231624
iterator(static_cast<Node*>(p.node), this, p.bucket), false);
16241625
// Case 2: insert.
16251626
if (this->ResizeIfLoadIsOutOfRange(this->num_elements_ + 1)) {
1626-
p = this->FindHelper(TS::ToView(k));
1627+
b = this->BucketNumber(TS::ToView(k));
16271628
}
1628-
const auto b = p.bucket; // bucket number
16291629
// If K is not key_type, make the conversion to key_type explicit.
16301630
using TypeToInit = typename std::conditional<
16311631
std::is_same<typename std::decay<K>::type, key_type>::value, K&&,

0 commit comments

Comments
 (0)