From 81c582a061591f000285916a329f7731b79385f1 Mon Sep 17 00:00:00 2001 From: Evan Brown Date: Wed, 18 Sep 2024 13:08:49 -0700 Subject: [PATCH] Change ExtensionSet::ForEach to return void instead of KeyValueFunctor. Motivation: this functionality is unused so we can simplify the code. PiperOrigin-RevId: 676102802 --- src/google/protobuf/extension_set.h | 55 +++++++++++++++-------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index 0daa4bbfc1..526522e84f 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -809,9 +809,9 @@ class PROTOBUF_EXPORT ExtensionSet { template - static KeyValueFunctor ForEachPrefetchImpl(Iterator it, Iterator end, - KeyValueFunctor func, - PrefetchFunctor prefetch_func) { + static void ForEachPrefetchImpl(Iterator it, Iterator end, + KeyValueFunctor func, + PrefetchFunctor prefetch_func) { // Note: based on arena's ChunkList::Cleanup(). // Prefetch distance 16 performs better than 8 in load tests. constexpr int kPrefetchDistance = 16; @@ -828,62 +828,63 @@ class PROTOBUF_EXPORT ExtensionSet { } // Call func on the rest without prefetching. for (; it != end; ++it) func(it->first, it->second); - return std::move(func); } - // Similar to std::for_each. + // Similar to std::for_each, but returning void. // Each Iterator is decomposed into ->first and ->second fields, so // that the KeyValueFunctor can be agnostic vis-a-vis KeyValue-vs-std::pair. // Applies a functor to the pairs in sorted order and // prefetches ahead. template - KeyValueFunctor ForEach(KeyValueFunctor func, PrefetchFunctor prefetch_func) { + void ForEach(KeyValueFunctor func, PrefetchFunctor prefetch_func) { if (PROTOBUF_PREDICT_FALSE(is_large())) { - return ForEachPrefetchImpl(map_.large->begin(), map_.large->end(), - std::move(func), std::move(prefetch_func)); + ForEachPrefetchImpl(map_.large->begin(), map_.large->end(), + std::move(func), std::move(prefetch_func)); + return; } - return ForEachPrefetchImpl(flat_begin(), flat_end(), std::move(func), - std::move(prefetch_func)); + ForEachPrefetchImpl(flat_begin(), flat_end(), std::move(func), + std::move(prefetch_func)); } // As above, but const. template - KeyValueFunctor ForEach(KeyValueFunctor func, - PrefetchFunctor prefetch_func) const { + void ForEach(KeyValueFunctor func, PrefetchFunctor prefetch_func) const { if (PROTOBUF_PREDICT_FALSE(is_large())) { - return ForEachPrefetchImpl(map_.large->begin(), map_.large->end(), - std::move(func), std::move(prefetch_func)); + ForEachPrefetchImpl(map_.large->begin(), map_.large->end(), + std::move(func), std::move(prefetch_func)); + return; } - return ForEachPrefetchImpl(flat_begin(), flat_end(), std::move(func), - std::move(prefetch_func)); + ForEachPrefetchImpl(flat_begin(), flat_end(), std::move(func), + std::move(prefetch_func)); } // As above, but without prefetching. This is for use in cases where we never // use the pointed-to extension values in `func`. template - static KeyValueFunctor ForEachNoPrefetch(Iterator begin, Iterator end, - KeyValueFunctor func) { + static void ForEachNoPrefetch(Iterator begin, Iterator end, + KeyValueFunctor func) { for (Iterator it = begin; it != end; ++it) func(it->first, it->second); - return std::move(func); } // Applies a functor to the pairs in sorted order. template - KeyValueFunctor ForEachNoPrefetch(KeyValueFunctor func) { + void ForEachNoPrefetch(KeyValueFunctor func) { if (PROTOBUF_PREDICT_FALSE(is_large())) { - return ForEachNoPrefetch(map_.large->begin(), map_.large->end(), - std::move(func)); + ForEachNoPrefetch(map_.large->begin(), map_.large->end(), + std::move(func)); + return; } - return ForEachNoPrefetch(flat_begin(), flat_end(), std::move(func)); + ForEachNoPrefetch(flat_begin(), flat_end(), std::move(func)); } // As above, but const. template - KeyValueFunctor ForEachNoPrefetch(KeyValueFunctor func) const { + void ForEachNoPrefetch(KeyValueFunctor func) const { if (PROTOBUF_PREDICT_FALSE(is_large())) { - return ForEachNoPrefetch(map_.large->begin(), map_.large->end(), - std::move(func)); + ForEachNoPrefetch(map_.large->begin(), map_.large->end(), + std::move(func)); + return; } - return ForEachNoPrefetch(flat_begin(), flat_end(), std::move(func)); + ForEachNoPrefetch(flat_begin(), flat_end(), std::move(func)); } // Merges existing Extension from other_extension