From db5c79932e16e97e8b2f9ecd0e74f99f0e74e0d7 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 20 Nov 2023 14:57:43 -0800 Subject: Make `FlatHashMapPolicy` return `std::true_type` for relocatable objects. This reduces produced binary size and can trigger even more optimizations in the future. PiperOrigin-RevId: 584136517 Change-Id: I3854833799f88f28b755ec53132925f0c3d468ab --- absl/container/internal/container_memory.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'absl/container/internal/container_memory.h') diff --git a/absl/container/internal/container_memory.h b/absl/container/internal/container_memory.h index f59ca4ee..3262d4eb 100644 --- a/absl/container/internal/container_memory.h +++ b/absl/container/internal/container_memory.h @@ -122,10 +122,10 @@ auto TupleRefImpl(T&& t, absl::index_sequence) // Returns a tuple of references to the elements of the input tuple. T must be a // tuple. template -auto TupleRef(T&& t) -> decltype( - TupleRefImpl(std::forward(t), - absl::make_index_sequence< - std::tuple_size::type>::value>())) { +auto TupleRef(T&& t) -> decltype(TupleRefImpl( + std::forward(t), + absl::make_index_sequence< + std::tuple_size::type>::value>())) { return TupleRefImpl( std::forward(t), absl::make_index_sequence< @@ -156,8 +156,8 @@ void ConstructFromTuple(Alloc* alloc, T* ptr, Tuple&& t) { // Constructs T using the args specified in the tuple and calls F with the // constructed value. template -decltype(std::declval()(std::declval())) WithConstructed( - Tuple&& t, F&& f) { +decltype(std::declval()(std::declval())) WithConstructed(Tuple&& t, + F&& f) { return memory_internal::WithConstructedImpl( std::forward(t), absl::make_index_sequence< @@ -423,16 +423,19 @@ struct map_slot_policy { } template - static void transfer(Allocator* alloc, slot_type* new_slot, + static auto transfer(Allocator* alloc, slot_type* new_slot, slot_type* old_slot) { + auto is_relocatable = + typename absl::is_trivially_relocatable::type(); + emplace(new_slot); #if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606 - if (absl::is_trivially_relocatable()) { + if (is_relocatable) { // TODO(b/247130232,b/251814870): remove casts after fixing warnings. std::memcpy(static_cast(std::launder(&new_slot->value)), static_cast(&old_slot->value), sizeof(value_type)); - return; + return is_relocatable; } #endif @@ -444,6 +447,7 @@ struct map_slot_policy { std::move(old_slot->value)); } destroy(alloc, old_slot); + return is_relocatable; } }; -- cgit v1.2.3