From 8c7b1ecd23aea88939d0e87efe7f2fd889ac40ce Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 10 Jun 2024 09:40:49 -0700 Subject: [PATCH] Replace FindHelper() with BucketNumber() when only the bucket number is required. PiperOrigin-RevId: 641931119 --- src/google/protobuf/map.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 5f85eb1797937..763582c05ec7c 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -972,13 +972,13 @@ class KeyMapBase : public UntypedMapBase { KeyNode* InsertOrReplaceNode(KeyNode* node) { KeyNode* to_erase = nullptr; auto p = this->FindHelper(node->key()); + map_index_t b = p.bucket; if (p.node != nullptr) { erase_no_destroy(p.bucket, static_cast(p.node)); to_erase = static_cast(p.node); } else if (ResizeIfLoadIsOutOfRange(num_elements_ + 1)) { - p = FindHelper(node->key()); + b = BucketNumber(node->key()); // bucket_number } - const map_index_t b = p.bucket; // bucket number InsertUnique(b, node); ++num_elements_; return to_erase; @@ -1617,15 +1617,15 @@ class Map : private internal::KeyMapBase> { template std::pair TryEmplaceInternal(K&& k, Args&&... args) { auto p = this->FindHelper(TS::ToView(k)); + internal::map_index_t b = p.bucket; // Case 1: key was already present. if (p.node != nullptr) return std::make_pair( iterator(static_cast(p.node), this, p.bucket), false); // Case 2: insert. if (this->ResizeIfLoadIsOutOfRange(this->num_elements_ + 1)) { - p = this->FindHelper(TS::ToView(k)); + b = this->BucketNumber(TS::ToView(k)); } - const auto b = p.bucket; // bucket number // If K is not key_type, make the conversion to key_type explicit. using TypeToInit = typename std::conditional< std::is_same::type, key_type>::value, K&&,