31 #include <google/protobuf/map_field.h>
32 #include <google/protobuf/map_field_inl.h>
36 #include <google/protobuf/port_def.inc>
61 auto other_state = other->
state_.load(std::memory_order_relaxed);
62 auto this_state =
state_.load(std::memory_order_relaxed);
63 other->
state_.store(this_state, std::memory_order_relaxed);
64 state_.store(other_state, std::memory_order_relaxed);
72 *
to = Arena::CreateMessage<RepeatedPtrField<Message> >(to_arena);
74 if (from_arena ==
nullptr) {
131 int state =
state_.load(std::memory_order_acquire);
137 int state =
state_.load(std::memory_order_acquire);
159 switch (
state_.load(std::memory_order_acquire)) {
174 if (
state_.load(std::memory_order_relaxed) ==
CLEAN) {
177 Arena::CreateMessage<RepeatedPtrField<Message> >(
arena_);
214 : default_entry_(default_entry) {}
217 : TypeDefinedMapFieldBase<MapKey, MapValueRef>(
arena),
219 default_entry_(default_entry) {}
222 if (
arena_ !=
nullptr)
return;
225 for (
auto& kv :
map_) {
226 kv.second.DeleteData();
238 iter->second.DeleteData();
260 map_val->SetType(val_des->cpp_type());
263 switch (val_des->cpp_type()) {
264 #define HANDLE_TYPE(CPPTYPE, TYPE) \
265 case FieldDescriptor::CPPTYPE_##CPPTYPE: { \
266 TYPE* value = Arena::Create<TYPE>(MapFieldBase::arena_); \
267 map_val->SetValue(value); \
284 map_val->SetValue(
value);
297 MapValueRef& map_val =
map_[map_key];
299 val->CopyFrom(map_val);
304 val->CopyFrom(
iter->second);
330 iter->second.DeleteData();
352 map_iter->key_.CopyFrom(
iter->first);
353 map_iter->value_.CopyFrom(
iter->second);
362 other_field.map_.begin();
363 other_it != other_field.map_.end(); ++other_it) {
365 MapValueRef* map_val;
367 map_val = &
map_[other_it->first];
370 map_val = &
iter->second;
376 switch (field_descriptor->cpp_type()) {
378 map_val->SetInt32Value(other_it->second.GetInt32Value());
382 map_val->SetInt64Value(other_it->second.GetInt64Value());
386 map_val->SetUInt32Value(other_it->second.GetUInt32Value());
390 map_val->SetUInt64Value(other_it->second.GetUInt64Value());
394 map_val->SetFloatValue(other_it->second.GetFloatValue());
398 map_val->SetDoubleValue(other_it->second.GetDoubleValue());
402 map_val->SetBoolValue(other_it->second.GetBoolValue());
406 map_val->SetStringValue(other_it->second.GetStringValue());
410 map_val->SetEnumValue(other_it->second.GetEnumValue());
414 map_val->MutableMessageValue()->CopyFrom(
415 other_it->second.GetMessageValue());
425 map_.swap(other_field->map_);
427 auto other_state = other_field->state_.load(std::memory_order_relaxed);
429 other_field->state_.store(this_state, std::memory_order_relaxed);
448 const MapKey& map_key =
it->first;
449 switch (key_des->cpp_type()) {
451 reflection->SetString(new_entry, key_des, map_key.GetStringValue());
454 reflection->SetInt64(new_entry, key_des, map_key.GetInt64Value());
457 reflection->SetInt32(new_entry, key_des, map_key.GetInt32Value());
460 reflection->SetUInt64(new_entry, key_des, map_key.GetUInt64Value());
463 reflection->SetUInt32(new_entry, key_des, map_key.GetUInt32Value());
466 reflection->SetBool(new_entry, key_des, map_key.GetBoolValue());
475 const MapValueRef& map_val =
it->second;
476 switch (val_des->cpp_type()) {
478 reflection->SetString(new_entry, val_des, map_val.GetStringValue());
481 reflection->SetInt64(new_entry, val_des, map_val.GetInt64Value());
484 reflection->SetInt32(new_entry, val_des, map_val.GetInt32Value());
487 reflection->SetUInt64(new_entry, val_des, map_val.GetUInt64Value());
490 reflection->SetUInt32(new_entry, val_des, map_val.GetUInt32Value());
493 reflection->SetBool(new_entry, val_des, map_val.GetBoolValue());
496 reflection->SetDouble(new_entry, val_des, map_val.GetDoubleValue());
499 reflection->SetFloat(new_entry, val_des, map_val.GetFloatValue());
502 reflection->SetEnumValue(new_entry, val_des, map_val.GetEnumValue());
506 reflection->MutableMessage(new_entry, val_des)->CopyFrom(
message);
523 iter->second.DeleteData();
532 switch (key_des->cpp_type()) {
534 map_key.SetStringValue(reflection->GetString(*
it, key_des));
537 map_key.SetInt64Value(reflection->GetInt64(*
it, key_des));
540 map_key.SetInt32Value(reflection->GetInt32(*
it, key_des));
543 map_key.SetUInt64Value(reflection->GetUInt64(*
it, key_des));
546 map_key.SetUInt32Value(reflection->GetUInt32(*
it, key_des));
549 map_key.SetBoolValue(reflection->GetBool(*
it, key_des));
563 iter->second.DeleteData();
567 MapValueRef& map_val = (*map)[map_key];
568 map_val.SetType(val_des->cpp_type());
569 switch (val_des->cpp_type()) {
570 #define HANDLE_TYPE(CPPTYPE, TYPE, METHOD) \
571 case FieldDescriptor::CPPTYPE_##CPPTYPE: { \
572 TYPE* value = Arena::Create<TYPE>(MapFieldBase::arena_); \
573 *value = reflection->Get##METHOD(*it, val_des); \
574 map_val.SetValue(value); \
591 map_val.SetValue(
value);
604 size_t map_size =
map_.size();
607 size +=
sizeof(
it->first) * map_size;
608 size +=
sizeof(
it->second) * map_size;
614 switch (
it->second.type()) {
615 #define HANDLE_TYPE(CPPTYPE, TYPE) \
616 case FieldDescriptor::CPPTYPE_##CPPTYPE: { \
617 size += sizeof(TYPE) * map_size; \
631 while (
it !=
map_.end()) {
647 #include <google/protobuf/port_undef.inc>