diff --git a/rust/cpp.rs b/rust/cpp.rs index 002567b2beeb..8c8ff3b89bda 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -1019,21 +1019,11 @@ where unsafe fn insert(m: RawMap, key: View<'_, Self>, value: MapValue) -> bool; - unsafe fn get( - m: RawMap, - prototype: MapValue, - key: View<'_, Self>, - value: *mut MapValue, - ) -> bool; - - unsafe fn iter_get( - iter: &mut UntypedMapIterator, - prototype: MapValue, - key: *mut Self::FfiKey, - value: *mut MapValue, - ); + unsafe fn get(m: RawMap, key: View<'_, Self>, value: *mut MapValue) -> bool; + + unsafe fn iter_get(iter: &mut UntypedMapIterator, key: *mut Self::FfiKey, value: *mut MapValue); - unsafe fn remove(m: RawMap, prototype: MapValue, key: View<'_, Self>) -> bool; + unsafe fn remove(m: RawMap, key: View<'_, Self>) -> bool; } macro_rules! generate_map_key_impl { @@ -1060,26 +1050,24 @@ macro_rules! generate_map_key_impl { #[inline] unsafe fn get( m: RawMap, - prototype: MapValue, key: View<'_, Self>, value: *mut MapValue, ) -> bool { - unsafe { [< proto2_rust_map_get_ $key >](m, prototype, $to_ffi(key), value) } + unsafe { [< proto2_rust_map_get_ $key >](m, $to_ffi(key), value) } } #[inline] unsafe fn iter_get( iter: &mut UntypedMapIterator, - prototype: MapValue, key: *mut Self::FfiKey, value: *mut MapValue, ) { - unsafe { [< proto2_rust_map_iter_get_ $key >](iter, prototype, key, value) } + unsafe { [< proto2_rust_map_iter_get_ $key >](iter, key, value) } } #[inline] - unsafe fn remove(m: RawMap, prototype: MapValue, key: View<'_, Self>) -> bool { - unsafe { [< proto2_rust_map_remove_ $key >](m, prototype, $to_ffi(key)) } + unsafe fn remove(m: RawMap, key: View<'_, Self>) -> bool { + unsafe { [< proto2_rust_map_remove_ $key >](m, $to_ffi(key)) } } } )* @@ -1136,9 +1124,7 @@ where fn map_get<'a>(map: MapView<'a, Key, Self>, key: View<'_, Key>) -> Option> { let mut value = std::mem::MaybeUninit::uninit(); - let found = unsafe { - Key::get(map.as_raw(Private), Self::get_prototype(), key, value.as_mut_ptr()) - }; + let found = unsafe { Key::get(map.as_raw(Private), key, value.as_mut_ptr()) }; if !found { return None; } @@ -1146,7 +1132,7 @@ where } fn map_remove(mut map: MapMut, key: View<'_, Key>) -> bool { - unsafe { Key::remove(map.as_raw(Private), Self::get_prototype(), key) } + unsafe { Key::remove(map.as_raw(Private), key) } } fn map_iter(map: MapView) -> MapIter { @@ -1169,7 +1155,7 @@ where // - The thunk does not increment the iterator. unsafe { iter.as_raw_mut(Private).next_unchecked::( - |iter, key, value| Key::iter_get(iter, Self::get_prototype(), key, value), + |iter, key, value| Key::iter_get(iter, key, value), |ffi_key| Key::to_view(ffi_key), |value| Self::from_map_value(value), ) @@ -1193,17 +1179,15 @@ macro_rules! impl_map_primitives { ) -> bool; pub fn $get_thunk( m: RawMap, - prototype: MapValue, key: $cpp_type, value: *mut MapValue, ) -> bool; pub fn $iter_get_thunk( iter: &mut UntypedMapIterator, - prototype: MapValue, key: *mut $cpp_type, value: *mut MapValue, ); - pub fn $remove_thunk(m: RawMap, prototype: MapValue, key: $cpp_type) -> bool; + pub fn $remove_thunk(m: RawMap, key: $cpp_type) -> bool; } )* }; diff --git a/rust/cpp_kernel/BUILD b/rust/cpp_kernel/BUILD index b428fbaa265d..f16566b80c4d 100644 --- a/rust/cpp_kernel/BUILD +++ b/rust/cpp_kernel/BUILD @@ -28,9 +28,9 @@ cc_library( "//src/google/protobuf", "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/io", + "@com_google_absl//absl/functional:overload", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", - "@com_google_absl//absl/strings:string_view", ], ) diff --git a/rust/cpp_kernel/map.cc b/rust/cpp_kernel/map.cc index 4f4786f945fb..e776599cf829 100644 --- a/rust/cpp_kernel/map.cc +++ b/rust/cpp_kernel/map.cc @@ -7,6 +7,7 @@ #include #include +#include "absl/functional/overload.h" #include "absl/log/absl_log.h" #include "google/protobuf/message.h" #include "google/protobuf/message_lite.h" @@ -48,75 +49,6 @@ template using KeyMap = internal::KeyMapBase< internal::KeyForBase::type>>; -void GetSizeAndAlignment(MapValue value, uint16_t* size, uint8_t* alignment) { - switch (value.tag) { - case MapValueTag::kBool: - *size = sizeof(bool); - *alignment = alignof(bool); - break; - case MapValueTag::kU32: - *size = sizeof(uint32_t); - *alignment = alignof(uint32_t); - break; - case MapValueTag::kU64: - *size = sizeof(uint64_t); - *alignment = alignof(uint64_t); - break; - case MapValueTag::kFloat: - *size = sizeof(float); - *alignment = alignof(float); - break; - case MapValueTag::kDouble: - *size = sizeof(double); - *alignment = alignof(double); - break; - case MapValueTag::kString: - *size = sizeof(std::string); - *alignment = alignof(std::string); - break; - case MapValueTag::kMessage: - internal::RustMapHelper::GetSizeAndAlignment(value.message, size, - alignment); - break; - default: - ABSL_DLOG(FATAL) << "Unexpected value of MapValue"; - } -} - -internal::MapNodeSizeInfoT GetSizeInfo(size_t key_size, MapValue value) { - // Each map node consists of a NodeBase followed by a std::pair. - // We need to compute the offset of the value and the total size of the node. - size_t node_and_key_size = sizeof(internal::NodeBase) + key_size; - uint16_t value_size; - uint8_t value_alignment; - GetSizeAndAlignment(value, &value_size, &value_alignment); - // Round node_and_key_size up to the nearest multiple of value_alignment. - uint16_t offset = - (((node_and_key_size - 1) / value_alignment) + 1) * value_alignment; - - size_t overall_alignment = std::max(alignof(internal::NodeBase), - static_cast(value_alignment)); - // Round up size to nearest multiple of overall_alignment. - size_t overall_size = - (((offset + value_size - 1) / overall_alignment) + 1) * overall_alignment; - - return internal::RustMapHelper::MakeSizeInfo(overall_size, offset); -} - -template -void DestroyMapNode(internal::UntypedMapBase* m, internal::NodeBase* node, - internal::MapNodeSizeInfoT size_info, - bool destroy_message) { - if constexpr (std::is_same::value) { - static_cast(node->GetVoidKey())->~basic_string(); - } - if (destroy_message) { - internal::RustMapHelper::DestroyMessage( - static_cast(node->GetVoidValue(size_info))); - } - internal::RustMapHelper::DeallocNode(m, node, size_info); -} - void InitializeMessageValue(void* raw_ptr, MessageLite* msg) { MessageLite* new_msg = internal::RustMapHelper::PlacementNew(msg, raw_ptr); auto* full_msg = DynamicCastMessage(new_msg); @@ -133,49 +65,34 @@ void InitializeMessageValue(void* raw_ptr, MessageLite* msg) { template bool Insert(internal::UntypedMapBase* m, Key key, MapValue value) { - internal::MapNodeSizeInfoT size_info = - GetSizeInfo(sizeof(typename FromViewType::type), value); - internal::NodeBase* node = internal::RustMapHelper::AllocNode(m, size_info); + internal::NodeBase* node = internal::RustMapHelper::AllocNode(m); if constexpr (std::is_same::value) { new (node->GetVoidKey()) std::string(key.ptr, key.len); } else { *static_cast(node->GetVoidKey()) = key; } - void* value_ptr = node->GetVoidValue(size_info); - switch (value.tag) { - case MapValueTag::kBool: - *static_cast(value_ptr) = value.b; - break; - case MapValueTag::kU32: - *static_cast(value_ptr) = value.u32; - break; - case MapValueTag::kU64: - *static_cast(value_ptr) = value.u64; - break; - case MapValueTag::kFloat: - *static_cast(value_ptr) = value.f32; - break; - case MapValueTag::kDouble: - *static_cast(value_ptr) = value.f64; - break; - case MapValueTag::kString: - new (value_ptr) std::string(std::move(*value.s)); - delete value.s; - break; - case MapValueTag::kMessage: - InitializeMessageValue(value_ptr, value.message); - break; - default: - ABSL_DLOG(FATAL) << "Unexpected value of MapValue"; - } + m->VisitValue(node, absl::Overload{ + [&](bool* v) { *v = value.b; }, + [&](uint32_t* v) { *v = value.u32; }, + [&](uint64_t* v) { *v = value.u64; }, + [&](float* v) { *v = value.f32; }, + [&](double* v) { *v = value.f64; }, + [&](std::string* str) { + new (str) std::string(std::move(*value.s)); + delete value.s; + }, + [&](MessageLite* msg) { + InitializeMessageValue(msg, value.message); + }, + }); node = internal::RustMapHelper::InsertOrReplaceNode( static_cast*>(m), node); if (node == nullptr) { return true; } - DestroyMapNode(m, node, size_info, value.tag == MapValueTag::kMessage); + internal::RustMapHelper::DeleteNode(m, node); return false; } @@ -194,89 +111,74 @@ internal::RustMapHelper::NodeAndBucket FindHelper(Map* m, m, absl::string_view(key.ptr, key.len)); } -void PopulateMapValue(MapValueTag tag, void* data, MapValue& output) { - output.tag = tag; - switch (tag) { - case MapValueTag::kBool: - output.b = *static_cast(data); - break; - case MapValueTag::kU32: - output.u32 = *static_cast(data); - break; - case MapValueTag::kU64: - output.u64 = *static_cast(data); - break; - case MapValueTag::kFloat: - output.f32 = *static_cast(data); - break; - case MapValueTag::kDouble: - output.f64 = *static_cast(data); - break; - case MapValueTag::kString: - output.s = static_cast(data); - break; - case MapValueTag::kMessage: - output.message = static_cast(data); - break; - default: - ABSL_DLOG(FATAL) << "Unexpected MapValueTag"; - } +void PopulateMapValue(const internal::UntypedMapBase& map, + internal::NodeBase* node, MapValue& output) { + map.VisitValue(node, absl::Overload{ + [&](const bool* v) { + output.tag = MapValueTag::kBool; + output.b = *v; + }, + [&](const uint32_t* v) { + output.tag = MapValueTag::kU32; + output.u32 = *v; + }, + [&](const uint64_t* v) { + output.tag = MapValueTag::kU64; + output.u64 = *v; + }, + [&](const float* v) { + output.tag = MapValueTag::kFloat; + output.f32 = *v; + }, + [&](const double* v) { + output.tag = MapValueTag::kDouble; + output.f64 = *v; + }, + [&](std::string* str) { + output.tag = MapValueTag::kString; + output.s = str; + }, + [&](MessageLite* msg) { + output.tag = MapValueTag::kMessage; + output.message = msg; + }, + }); } template -bool Get(internal::UntypedMapBase* m, MapValue prototype, Key key, - MapValue* value) { - internal::MapNodeSizeInfoT size_info = - GetSizeInfo(sizeof(typename FromViewType::type), prototype); +bool Get(internal::UntypedMapBase* m, Key key, MapValue* value) { auto* map_base = static_cast*>(m); internal::RustMapHelper::NodeAndBucket result = FindHelper(map_base, key); if (result.node == nullptr) { return false; } - PopulateMapValue(prototype.tag, result.node->GetVoidValue(size_info), *value); + PopulateMapValue(*m, result.node, *value); return true; } template -bool Remove(internal::UntypedMapBase* m, MapValue prototype, Key key) { - internal::MapNodeSizeInfoT size_info = - GetSizeInfo(sizeof(typename FromViewType::type), prototype); +bool Remove(internal::UntypedMapBase* m, Key key) { auto* map_base = static_cast*>(m); internal::RustMapHelper::NodeAndBucket result = FindHelper(map_base, key); if (result.node == nullptr) { return false; } internal::RustMapHelper::EraseNoDestroy(map_base, result.bucket, result.node); - DestroyMapNode(m, result.node, size_info, - prototype.tag == MapValueTag::kMessage); + internal::RustMapHelper::DeleteNode(m, result.node); return true; } template -void IterGet(const internal::UntypedMapIterator* iter, MapValue prototype, - Key* key, MapValue* value) { - internal::MapNodeSizeInfoT size_info = - GetSizeInfo(sizeof(typename FromViewType::type), prototype); +void IterGet(const internal::UntypedMapIterator* iter, Key* key, + MapValue* value) { internal::NodeBase* node = iter->node_; if constexpr (std::is_same::value) { - const std::string* s = static_cast(node->GetVoidKey()); + const std::string* s = iter->m_->GetKey(node); *key = PtrAndLen{s->data(), s->size()}; } else { - *key = *static_cast(node->GetVoidKey()); - } - PopulateMapValue(prototype.tag, node->GetVoidValue(size_info), *value); -} - -// Returns the size of the key in the map entry, given the key used for FFI. -// The map entry key and FFI key are always the same, except in the case of -// string and bytes. -template -size_t KeySize() { - if constexpr (std::is_same::value) { - return sizeof(std::string); - } else { - return sizeof(Key); + *key = *iter->m_->GetKey(node); } + PopulateMapValue(*iter->m_, node, *value); } } // namespace @@ -321,30 +223,28 @@ void proto2_rust_map_clear(google::protobuf::internal::UntypedMapBase* m) { m->ClearTable(true, nullptr); } -#define DEFINE_KEY_SPECIFIC_MAP_OPERATIONS(cpp_type, suffix) \ - bool proto2_rust_map_insert_##suffix(google::protobuf::internal::UntypedMapBase* m, \ - cpp_type key, \ - google::protobuf::rust::MapValue value) { \ - return google::protobuf::rust::Insert(m, key, value); \ - } \ - \ - bool proto2_rust_map_get_##suffix( \ - google::protobuf::internal::UntypedMapBase* m, google::protobuf::rust::MapValue prototype, \ - cpp_type key, google::protobuf::rust::MapValue* value) { \ - return google::protobuf::rust::Get(m, prototype, key, value); \ - } \ - \ - bool proto2_rust_map_remove_##suffix(google::protobuf::internal::UntypedMapBase* m, \ - google::protobuf::rust::MapValue prototype, \ - cpp_type key) { \ - return google::protobuf::rust::Remove(m, prototype, key); \ - } \ - \ - void proto2_rust_map_iter_get_##suffix( \ - const google::protobuf::internal::UntypedMapIterator* iter, \ - google::protobuf::rust::MapValue prototype, cpp_type* key, \ - google::protobuf::rust::MapValue* value) { \ - return google::protobuf::rust::IterGet(iter, prototype, key, value); \ +#define DEFINE_KEY_SPECIFIC_MAP_OPERATIONS(cpp_type, suffix) \ + bool proto2_rust_map_insert_##suffix(google::protobuf::internal::UntypedMapBase* m, \ + cpp_type key, \ + google::protobuf::rust::MapValue value) { \ + return google::protobuf::rust::Insert(m, key, value); \ + } \ + \ + bool proto2_rust_map_get_##suffix(google::protobuf::internal::UntypedMapBase* m, \ + cpp_type key, \ + google::protobuf::rust::MapValue* value) { \ + return google::protobuf::rust::Get(m, key, value); \ + } \ + \ + bool proto2_rust_map_remove_##suffix(google::protobuf::internal::UntypedMapBase* m, \ + cpp_type key) { \ + return google::protobuf::rust::Remove(m, key); \ + } \ + \ + void proto2_rust_map_iter_get_##suffix( \ + const google::protobuf::internal::UntypedMapIterator* iter, cpp_type* key, \ + google::protobuf::rust::MapValue* value) { \ + return google::protobuf::rust::IterGet(iter, key, value); \ } DEFINE_KEY_SPECIFIC_MAP_OPERATIONS(int32_t, i32) diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index 5c47cbebb5c9..45ec731938d4 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -1010,13 +1010,6 @@ class PROTOBUF_EXPORT TcParser final { uint32_t tag, NodeBase* node, MapAuxInfo map_info); - static void InitializeMapNodeEntry(void* obj, MapTypeCard type_card, - UntypedMapBase& map, - const TcParseTableBase::FieldAux* aux, - bool is_key); - PROTOBUF_NOINLINE - static void DestroyMapNode(NodeBase* node, MapAuxInfo map_info, - UntypedMapBase& map); static const char* ParseOneMapEntry(NodeBase* node, const char* ptr, ParseContext* ctx, const TcParseTableBase::FieldAux* aux, diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index 32c3199fe28a..ed01ff9b7a88 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -16,6 +16,7 @@ #include #include "absl/base/optimization.h" +#include "absl/functional/overload.h" #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/numeric/bits.h" @@ -2681,48 +2682,6 @@ void TcParser::WriteMapEntryAsUnknown(MessageLite* msg, GetUnknownFieldOps(table).write_length_delimited(msg, tag >> 3, serialized); } -PROTOBUF_ALWAYS_INLINE void TcParser::InitializeMapNodeEntry( - void* obj, MapTypeCard type_card, UntypedMapBase& map, - const TcParseTableBase::FieldAux* aux, bool is_key) { - (void)is_key; - switch (type_card.cpp_type()) { - case MapTypeCard::kBool: - memset(obj, 0, sizeof(bool)); - break; - case MapTypeCard::k32: - memset(obj, 0, sizeof(uint32_t)); - break; - case MapTypeCard::k64: - memset(obj, 0, sizeof(uint64_t)); - break; - case MapTypeCard::kString: - Arena::CreateInArenaStorage(reinterpret_cast(obj), - map.arena()); - break; - case MapTypeCard::kMessage: - aux[1].table->class_data->PlacementNew(obj, map.arena()); - break; - default: - Unreachable(); - } -} - -PROTOBUF_NOINLINE void TcParser::DestroyMapNode(NodeBase* node, - MapAuxInfo map_info, - UntypedMapBase& map) { - if (map_info.key_type_card.cpp_type() == MapTypeCard::kString) { - static_cast(node->GetVoidKey())->~basic_string(); - } - if (map_info.value_type_card.cpp_type() == MapTypeCard::kString) { - static_cast(node->GetVoidValue(map_info.node_size_info)) - ->~basic_string(); - } else if (map_info.value_type_card.cpp_type() == MapTypeCard::kMessage) { - static_cast(node->GetVoidValue(map_info.node_size_info)) - ->DestroyInstance(); - } - map.DeallocNode(node, map_info.node_size_info); -} - template const char* ReadFixed(void* obj, const char* ptr) { auto v = UnalignedLoad(ptr); @@ -2866,12 +2825,38 @@ PROTOBUF_NOINLINE const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) { const uint32_t saved_tag = data.tag(); while (true) { - NodeBase* node = map.AllocNode(map_info.node_size_info); - - InitializeMapNodeEntry(node->GetVoidKey(), map_info.key_type_card, map, aux, - true); - InitializeMapNodeEntry(node->GetVoidValue(map_info.node_size_info), - map_info.value_type_card, map, aux, false); + NodeBase* node = map.AllocNode(); + + map.VisitKey(node, // + absl::Overload{ + [&](std::string* str) { + Arena::CreateInArenaStorage(str, map.arena()); + }, + [&](void* scalar) { + // Due to node alignment we can guarantee that we have at + // least 8 writable bytes at the key position (as long as + // we do it before we initialize the value). We can + // unconditionally write here. + // Assert this in debug mode, just in case. + ABSL_DCHECK_GE( + reinterpret_cast(node) + + map.type_info().node_size - + reinterpret_cast(node->GetVoidKey()), + sizeof(uint64_t)); + memset(node->GetVoidKey(), 0, sizeof(uint64_t)); + }, + }); + + map.VisitValue( + node, absl::Overload{ + [&](std::string* str) { + Arena::CreateInArenaStorage(str, map.arena()); + }, + [&](MessageLite* msg) { + aux[1].table->class_data->PlacementNew(msg, map.arena()); + }, + [](auto* scalar) { memset(scalar, 0, sizeof(*scalar)); }, + }); ptr = ctx->ParseLengthDelimitedInlined(ptr, [&](const char* ptr) { return ParseOneMapEntry(node, ptr, ctx, aux, table, entry, map.arena()); @@ -2915,7 +2900,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) { // It could be because we failed to parse, or because insertion returned // an overwritten node. if (ABSL_PREDICT_FALSE(node != nullptr && map.arena() == nullptr)) { - DestroyMapNode(node, map_info, map); + map.DeleteNode(node); } if (ABSL_PREDICT_FALSE(ptr == nullptr)) { diff --git a/src/google/protobuf/map.cc b/src/google/protobuf/map.cc index c2e8c060251a..5d19ea6fd931 100644 --- a/src/google/protobuf/map.cc +++ b/src/google/protobuf/map.cc @@ -30,6 +30,15 @@ namespace internal { NodeBase* const kGlobalEmptyTable[kGlobalEmptyTableSize] = {}; +void UntypedMapBase::DeleteNode(NodeBase* node) { + const auto destroy = absl::Overload{ + [](std::string* str) { str->~basic_string(); }, + [](MessageLite* msg) { msg->DestroyInstance(); }, [](void*) {}}; + VisitKey(node, destroy); + VisitValue(node, destroy); + DeallocNode(node); +} + void UntypedMapBase::ClearTableImpl(bool reset, void (*destroy)(NodeBase*)) { ABSL_DCHECK_NE(num_buckets_, kGlobalEmptyTableSize); diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 1a3f7cc12ac1..a54d67e1a49f 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -456,6 +456,8 @@ class PROTOBUF_EXPORT UntypedMapBase { // Space used for the table and nodes. size_t SpaceUsedExcludingSelfLong() const; + TypeInfo type_info() const { return type_info_; } + protected: // 16 bytes is the minimum useful size for the array cache in the arena. enum : map_index_t { kMinTableSize = 16 / sizeof(void*) }; @@ -544,18 +546,14 @@ class PROTOBUF_EXPORT UntypedMapBase { using AllocFor = absl::allocator_traits::template rebind_alloc; // Alignment of the nodes is the same as alignment of NodeBase. - NodeBase* AllocNode(MapNodeSizeInfoT size_info) { - return AllocNode(SizeFromInfo(size_info)); - } + NodeBase* AllocNode() { return AllocNode(type_info_.node_size); } NodeBase* AllocNode(size_t node_size) { PROTOBUF_ASSUME(node_size % sizeof(NodeBase) == 0); return AllocFor(alloc_).allocate(node_size / sizeof(NodeBase)); } - void DeallocNode(NodeBase* node, MapNodeSizeInfoT size_info) { - DeallocNode(node, SizeFromInfo(size_info)); - } + void DeallocNode(NodeBase* node) { DeallocNode(node, type_info_.node_size); } void DeallocNode(NodeBase* node, size_t node_size) { PROTOBUF_ASSUME(node_size % sizeof(NodeBase) == 0); @@ -578,6 +576,8 @@ class PROTOBUF_EXPORT UntypedMapBase { return result; } + void DeleteNode(NodeBase* node); + template static void DestroyNode(NodeBase* node) { static_cast(node)->~Node(); @@ -963,30 +963,10 @@ class RustMapHelper { public: using NodeAndBucket = UntypedMapBase::NodeAndBucket; - static void GetSizeAndAlignment(const google::protobuf::MessageLite* m, uint16_t* size, - uint8_t* alignment) { - const auto* class_data = m->GetClassData(); - *size = static_cast(class_data->allocation_size()); - *alignment = class_data->alignment(); - } - - static constexpr MapNodeSizeInfoT MakeSizeInfo(uint16_t size, - uint16_t value_offset) { - return MakeNodeInfo(size, value_offset); - } - - template - static constexpr MapNodeSizeInfoT SizeInfo() { - return Map::Node::size_info(); - } - - static NodeBase* AllocNode(UntypedMapBase* m, MapNodeSizeInfoT size_info) { - return m->AllocNode(size_info); - } + static NodeBase* AllocNode(UntypedMapBase* m) { return m->AllocNode(); } - static void DeallocNode(UntypedMapBase* m, NodeBase* node, - MapNodeSizeInfoT size_info) { - return m->DeallocNode(node, size_info); + static void DeleteNode(UntypedMapBase* m, NodeBase* node) { + return m->DeleteNode(node); } template @@ -1008,12 +988,6 @@ class RustMapHelper { void* mem) { return prototype->GetClassData()->PlacementNew(mem, /* arena = */ nullptr); } - - static void DestroyMessage(MessageLite* m) { m->DestroyInstance(); } - - static bool IsGlobalEmptyTable(const UntypedMapBase* m) { - return m->num_buckets_ == kGlobalEmptyTableSize; - } }; } // namespace internal @@ -1422,7 +1396,7 @@ class Map : private internal::KeyMapBase> { ABSL_DCHECK_EQ(pos.m_, static_cast(this)); auto* node = static_cast(pos.node_); this->erase_no_destroy(pos.bucket_index_, node); - DestroyNode(node); + DeleteNode(node); return next; } @@ -1494,7 +1468,7 @@ class Map : private internal::KeyMapBase> { }; } - void DestroyNode(Node* node) { + void DeleteNode(Node* node) { if (this->alloc_.arena() == nullptr) { node->kv.first.~key_type(); node->kv.second.~mapped_type();