InternalSwap does not need two arenas, since they are required to be the same

one.

PiperOrigin-RevId: 567293489
pull/14147/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent e71ce645d2
commit 1de33336cd
  1. 22
      src/google/protobuf/arenastring.h
  2. 36
      src/google/protobuf/arenastring_unittest.cc
  3. 7
      src/google/protobuf/compiler/cpp/field_generators/string_field.cc
  4. 7
      src/google/protobuf/compiler/cpp/message.cc
  5. 34
      src/google/protobuf/compiler/plugin.pb.cc
  6. 191
      src/google/protobuf/descriptor.pb.cc
  7. 11
      src/google/protobuf/generated_message_reflection.cc
  8. 20
      src/google/protobuf/inlined_string_field.h

@ -374,9 +374,8 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// logic in Swap()/UnsafeArenaSwap() at the message level, so this method is
// 'unsafe' if called directly.
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(ArenaStringPtr* rhs,
Arena* rhs_arena,
ArenaStringPtr* lhs,
Arena* lhs_arena);
Arena* arena);
// Internal setter used only at parse time to directly set a donated string
// value.
@ -496,17 +495,14 @@ inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) {
Set(absl::string_view{static_cast<const char*>(p), n}, arena);
}
// Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs.
inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( //
ArenaStringPtr* rhs, Arena* rhs_arena, //
ArenaStringPtr* lhs, Arena* lhs_arena) {
inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap(
ArenaStringPtr* rhs, ArenaStringPtr* lhs, Arena* arena) {
// Silence unused variable warnings in release buildls.
(void)rhs_arena;
(void)lhs_arena;
(void)arena;
std::swap(lhs->tagged_ptr_, rhs->tagged_ptr_);
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
auto force_realloc = [](ArenaStringPtr* p, Arena* arena) {
if (p->IsDefault()) return;
for (auto* p : {lhs, rhs}) {
if (p->IsDefault()) continue;
std::string* old_value = p->tagged_ptr_.Get();
std::string* new_value =
p->IsFixedSizeArena()
@ -518,11 +514,7 @@ inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( //
} else {
p->tagged_ptr_.SetMutableArena(new_value);
}
};
// Because, at this point, tagged_ptr_ has been swapped, arena should also be
// swapped.
force_realloc(lhs, rhs_arena);
force_realloc(rhs, lhs_arena);
}
#endif // PROTOBUF_FORCE_COPY_IN_SWAP
}

@ -89,42 +89,6 @@ TEST_P(SingleArena, NullDefault) {
field.Destroy();
}
class DualArena : public testing::TestWithParam<std::tuple<bool, bool>> {
public:
std::unique_ptr<Arena> GetLhsArena() {
if (std::get<0>(this->GetParam())) return nullptr;
return std::unique_ptr<Arena>(new Arena());
}
std::unique_ptr<Arena> GetRhsArena() {
if (std::get<1>(this->GetParam())) return nullptr;
return std::unique_ptr<Arena>(new Arena());
}
};
INSTANTIATE_TEST_SUITE_P(ArenaString, DualArena,
testing::Combine(testing::Bool(), testing::Bool()));
TEST_P(DualArena, Swap) {
auto lhs_arena = GetLhsArena();
ArenaStringPtr lhs;
lhs.InitDefault();
ArenaStringPtr rhs;
rhs.InitDefault();
{
auto rhs_arena = GetRhsArena();
lhs.Set("lhs value that has some heft", lhs_arena.get());
rhs.Set("rhs value that has some heft", rhs_arena.get());
ArenaStringPtr::InternalSwap(&lhs, lhs_arena.get(), //
&rhs, rhs_arena.get());
EXPECT_EQ("rhs value that has some heft", lhs.Get());
EXPECT_EQ("lhs value that has some heft", rhs.Get());
lhs.Destroy();
}
EXPECT_EQ("lhs value that has some heft", rhs.Get());
rhs.Destroy();
}
TEST(ArenaStringPtrTest, ConstInit) {
// Verify that we can constinit construct an ArenaStringPtr from an arbitrary
// ExplicitlyConstructed<std::string>*.

@ -571,8 +571,7 @@ void SingularString::GenerateSwappingCode(io::Printer* p) const {
if (!is_inlined()) {
p->Emit(R"cc(
::_pbi::ArenaStringPtr::InternalSwap(&$field_$, lhs_arena,
&other->$field_$, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&$field_$, &other->$field_$, arena);
)cc");
return;
}
@ -583,8 +582,8 @@ void SingularString::GenerateSwappingCode(io::Printer* p) const {
bool rhs_dtor_registered =
(other->$inlined_string_donated_array$[0] & 1) == 0;
::_pbi::InlinedStringField::InternalSwap(
&$field_$, lhs_arena, lhs_dtor_registered, this, &other->$field_$,
rhs_arena, rhs_dtor_registered, other);
&$field_$, lhs_dtor_registered, this, &other->$field_$,
rhs_dtor_registered, other, arena);
}
)cc");
}

@ -3824,9 +3824,10 @@ void MessageGenerator::GenerateSwap(io::Printer* p) {
}
if (HasNonSplitOptionalString(descriptor_, options_)) {
format(
"auto* lhs_arena = GetArenaForAllocation();\n"
"auto* rhs_arena = other->GetArenaForAllocation();\n");
p->Emit(R"cc(
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
)cc");
}
format("_internal_metadata_.InternalSwap(&other->_internal_metadata_);\n");

@ -592,12 +592,11 @@ PROTOBUF_NOINLINE bool Version::IsInitialized() const {
}
void Version::InternalSwap(Version* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.suffix_, lhs_arena,
&other->_impl_.suffix_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.suffix_, &other->_impl_.suffix_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(Version, _impl_.patch_)
+ sizeof(Version::_impl_.patch_)
@ -941,15 +940,14 @@ PROTOBUF_NOINLINE bool CodeGeneratorRequest::IsInitialized() const {
}
void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.file_to_generate_.InternalSwap(&other->_impl_.file_to_generate_);
_impl_.proto_file_.InternalSwap(&other->_impl_.proto_file_);
_impl_.source_file_descriptors_.InternalSwap(&other->_impl_.source_file_descriptors_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.parameter_, lhs_arena,
&other->_impl_.parameter_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.parameter_, &other->_impl_.parameter_, arena);
swap(_impl_.compiler_version_, other->_impl_.compiler_version_);
}
@ -1269,16 +1267,13 @@ PROTOBUF_NOINLINE bool CodeGeneratorResponse_File::IsInitialized() const {
}
void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.insertion_point_, lhs_arena,
&other->_impl_.insertion_point_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.content_, lhs_arena,
&other->_impl_.content_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.insertion_point_, &other->_impl_.insertion_point_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.content_, &other->_impl_.content_, arena);
swap(_impl_.generated_code_info_, other->_impl_.generated_code_info_);
}
@ -1539,13 +1534,12 @@ PROTOBUF_NOINLINE bool CodeGeneratorResponse::IsInitialized() const {
}
void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.file_.InternalSwap(&other->_impl_.file_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.error_, lhs_arena,
&other->_impl_.error_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.error_, &other->_impl_.error_, arena);
swap(_impl_.supported_features_, other->_impl_.supported_features_);
}

@ -3135,8 +3135,8 @@ PROTOBUF_NOINLINE bool FileDescriptorProto::IsInitialized() const {
}
void FileDescriptorProto::InternalSwap(FileDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.dependency_.InternalSwap(&other->_impl_.dependency_);
@ -3146,14 +3146,10 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* PROTOBUF_RESTRICT ot
_impl_.extension_.InternalSwap(&other->_impl_.extension_);
_impl_.public_dependency_.InternalSwap(&other->_impl_.public_dependency_);
_impl_.weak_dependency_.InternalSwap(&other->_impl_.weak_dependency_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.package_, lhs_arena,
&other->_impl_.package_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.syntax_, lhs_arena,
&other->_impl_.syntax_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.edition_, lhs_arena,
&other->_impl_.edition_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.package_, &other->_impl_.package_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.syntax_, &other->_impl_.syntax_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.edition_, &other->_impl_.edition_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(FileDescriptorProto, _impl_.edition_enum_)
+ sizeof(FileDescriptorProto::_impl_.edition_enum_)
@ -4148,8 +4144,8 @@ PROTOBUF_NOINLINE bool DescriptorProto::IsInitialized() const {
}
void DescriptorProto::InternalSwap(DescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.field_.InternalSwap(&other->_impl_.field_);
@ -4160,8 +4156,7 @@ void DescriptorProto::InternalSwap(DescriptorProto* PROTOBUF_RESTRICT other) {
_impl_.oneof_decl_.InternalSwap(&other->_impl_.oneof_decl_);
_impl_.reserved_range_.InternalSwap(&other->_impl_.reserved_range_);
_impl_.reserved_name_.InternalSwap(&other->_impl_.reserved_name_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
swap(_impl_.options_, other->_impl_.options_);
}
@ -4496,14 +4491,12 @@ PROTOBUF_NOINLINE bool ExtensionRangeOptions_Declaration::IsInitialized() const
}
void ExtensionRangeOptions_Declaration::InternalSwap(ExtensionRangeOptions_Declaration* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.full_name_, lhs_arena,
&other->_impl_.full_name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.type_, lhs_arena,
&other->_impl_.type_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.full_name_, &other->_impl_.full_name_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.type_, &other->_impl_.type_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(ExtensionRangeOptions_Declaration, _impl_.repeated_)
+ sizeof(ExtensionRangeOptions_Declaration::_impl_.repeated_)
@ -5377,20 +5370,15 @@ PROTOBUF_NOINLINE bool FieldDescriptorProto::IsInitialized() const {
}
void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.extendee_, lhs_arena,
&other->_impl_.extendee_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.type_name_, lhs_arena,
&other->_impl_.type_name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.default_value_, lhs_arena,
&other->_impl_.default_value_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.json_name_, lhs_arena,
&other->_impl_.json_name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.extendee_, &other->_impl_.extendee_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.type_name_, &other->_impl_.type_name_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.default_value_, &other->_impl_.default_value_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.json_name_, &other->_impl_.json_name_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(FieldDescriptorProto, _impl_.type_)
+ sizeof(FieldDescriptorProto::_impl_.type_)
@ -5646,12 +5634,11 @@ PROTOBUF_NOINLINE bool OneofDescriptorProto::IsInitialized() const {
}
void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
swap(_impl_.options_, other->_impl_.options_);
}
@ -6209,15 +6196,14 @@ PROTOBUF_NOINLINE bool EnumDescriptorProto::IsInitialized() const {
}
void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.value_.InternalSwap(&other->_impl_.value_);
_impl_.reserved_range_.InternalSwap(&other->_impl_.reserved_range_);
_impl_.reserved_name_.InternalSwap(&other->_impl_.reserved_name_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
swap(_impl_.options_, other->_impl_.options_);
}
@ -6502,12 +6488,11 @@ PROTOBUF_NOINLINE bool EnumValueDescriptorProto::IsInitialized() const {
}
void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(EnumValueDescriptorProto, _impl_.number_)
+ sizeof(EnumValueDescriptorProto::_impl_.number_)
@ -6792,13 +6777,12 @@ PROTOBUF_NOINLINE bool ServiceDescriptorProto::IsInitialized() const {
}
void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.method_.InternalSwap(&other->_impl_.method_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
swap(_impl_.options_, other->_impl_.options_);
}
@ -7181,16 +7165,13 @@ PROTOBUF_NOINLINE bool MethodDescriptorProto::IsInitialized() const {
}
void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, lhs_arena,
&other->_impl_.name_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.input_type_, lhs_arena,
&other->_impl_.input_type_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.output_type_, lhs_arena,
&other->_impl_.output_type_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.input_type_, &other->_impl_.input_type_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.output_type_, &other->_impl_.output_type_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(MethodDescriptorProto, _impl_.server_streaming_)
+ sizeof(MethodDescriptorProto::_impl_.server_streaming_)
@ -8070,31 +8051,21 @@ PROTOBUF_NOINLINE bool FileOptions::IsInitialized() const {
void FileOptions::InternalSwap(FileOptions* PROTOBUF_RESTRICT other) {
using std::swap;
_impl_._extensions_.InternalSwap(&other->_impl_._extensions_);
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.uninterpreted_option_.InternalSwap(&other->_impl_.uninterpreted_option_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.java_package_, lhs_arena,
&other->_impl_.java_package_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.java_outer_classname_, lhs_arena,
&other->_impl_.java_outer_classname_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.go_package_, lhs_arena,
&other->_impl_.go_package_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.objc_class_prefix_, lhs_arena,
&other->_impl_.objc_class_prefix_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.csharp_namespace_, lhs_arena,
&other->_impl_.csharp_namespace_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.swift_prefix_, lhs_arena,
&other->_impl_.swift_prefix_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.php_class_prefix_, lhs_arena,
&other->_impl_.php_class_prefix_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.php_namespace_, lhs_arena,
&other->_impl_.php_namespace_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.php_metadata_namespace_, lhs_arena,
&other->_impl_.php_metadata_namespace_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.ruby_package_, lhs_arena,
&other->_impl_.ruby_package_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.java_package_, &other->_impl_.java_package_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.java_outer_classname_, &other->_impl_.java_outer_classname_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.go_package_, &other->_impl_.go_package_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.objc_class_prefix_, &other->_impl_.objc_class_prefix_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.csharp_namespace_, &other->_impl_.csharp_namespace_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.swift_prefix_, &other->_impl_.swift_prefix_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.php_class_prefix_, &other->_impl_.php_class_prefix_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.php_namespace_, &other->_impl_.php_namespace_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.php_metadata_namespace_, &other->_impl_.php_metadata_namespace_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.ruby_package_, &other->_impl_.ruby_package_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.cc_enable_arenas_)
+ sizeof(FileOptions::_impl_.cc_enable_arenas_)
@ -8769,14 +8740,12 @@ PROTOBUF_NOINLINE bool FieldOptions_EditionDefault::IsInitialized() const {
}
void FieldOptions_EditionDefault::InternalSwap(FieldOptions_EditionDefault* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.edition_, lhs_arena,
&other->_impl_.edition_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.value_, lhs_arena,
&other->_impl_.value_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.edition_, &other->_impl_.edition_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.value_, &other->_impl_.value_, arena);
swap(_impl_.edition_enum_, other->_impl_.edition_enum_);
}
@ -11167,12 +11136,11 @@ PROTOBUF_NOINLINE bool UninterpretedOption_NamePart::IsInitialized() const {
}
void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_part_, lhs_arena,
&other->_impl_.name_part_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_part_, &other->_impl_.name_part_, arena);
swap(_impl_.is_extension_, other->_impl_.is_extension_);
}
@ -11563,17 +11531,14 @@ PROTOBUF_NOINLINE bool UninterpretedOption::IsInitialized() const {
}
void UninterpretedOption::InternalSwap(UninterpretedOption* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.name_.InternalSwap(&other->_impl_.name_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.identifier_value_, lhs_arena,
&other->_impl_.identifier_value_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.string_value_, lhs_arena,
&other->_impl_.string_value_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.aggregate_value_, lhs_arena,
&other->_impl_.aggregate_value_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.identifier_value_, &other->_impl_.identifier_value_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.string_value_, &other->_impl_.string_value_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.aggregate_value_, &other->_impl_.aggregate_value_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(UninterpretedOption, _impl_.double_value_)
+ sizeof(UninterpretedOption::_impl_.double_value_)
@ -12205,12 +12170,11 @@ PROTOBUF_NOINLINE bool FeatureSetDefaults_FeatureSetEditionDefault::IsInitialize
}
void FeatureSetDefaults_FeatureSetEditionDefault::InternalSwap(FeatureSetDefaults_FeatureSetEditionDefault* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.edition_, lhs_arena,
&other->_impl_.edition_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.edition_, &other->_impl_.edition_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(FeatureSetDefaults_FeatureSetEditionDefault, _impl_.edition_enum_)
+ sizeof(FeatureSetDefaults_FeatureSetEditionDefault::_impl_.edition_enum_)
@ -12556,15 +12520,13 @@ PROTOBUF_NOINLINE bool FeatureSetDefaults::IsInitialized() const {
}
void FeatureSetDefaults::InternalSwap(FeatureSetDefaults* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.defaults_.InternalSwap(&other->_impl_.defaults_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.minimum_edition_, lhs_arena,
&other->_impl_.minimum_edition_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.maximum_edition_, lhs_arena,
&other->_impl_.maximum_edition_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.minimum_edition_, &other->_impl_.minimum_edition_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.maximum_edition_, &other->_impl_.maximum_edition_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(FeatureSetDefaults, _impl_.maximum_edition_enum_)
+ sizeof(FeatureSetDefaults::_impl_.maximum_edition_enum_)
@ -12905,17 +12867,15 @@ PROTOBUF_NOINLINE bool SourceCodeInfo_Location::IsInitialized() const {
}
void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.path_.InternalSwap(&other->_impl_.path_);
_impl_.span_.InternalSwap(&other->_impl_.span_);
_impl_.leading_detached_comments_.InternalSwap(&other->_impl_.leading_detached_comments_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.leading_comments_, lhs_arena,
&other->_impl_.leading_comments_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.trailing_comments_, lhs_arena,
&other->_impl_.trailing_comments_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.leading_comments_, &other->_impl_.leading_comments_, arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.trailing_comments_, &other->_impl_.trailing_comments_, arena);
}
::google::protobuf::Metadata SourceCodeInfo_Location::GetMetadata() const {
@ -13432,13 +13392,12 @@ PROTOBUF_NOINLINE bool GeneratedCodeInfo_Annotation::IsInitialized() const {
}
void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* PROTOBUF_RESTRICT other) {
using std::swap;
auto* lhs_arena = GetArenaForAllocation();
auto* rhs_arena = other->GetArenaForAllocation();
auto* arena = GetArenaForAllocation();
ABSL_DCHECK_EQ(arena, other->GetArenaForAllocation());
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
_impl_.path_.InternalSwap(&other->_impl_.path_);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.source_file_, lhs_arena,
&other->_impl_.source_file_, rhs_arena);
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.source_file_, &other->_impl_.source_file_, arena);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_.semantic_)
+ sizeof(GeneratedCodeInfo_Annotation::_impl_.semantic_)

@ -640,10 +640,11 @@ void SwapFieldHelper::SwapInlinedStrings(const Reflection* r, Message* lhs,
bool lhs_arena_dtor_registered = (lhs_array[0] & 0x1u) == 0;
bool rhs_arena_dtor_registered = (rhs_array[0] & 0x1u) == 0;
const uint32_t mask = ~(static_cast<uint32_t>(1) << (index % 32));
if (unsafe_shallow_swap || lhs_arena == rhs_arena) {
InlinedStringField::InternalSwap(lhs_string, lhs_arena,
lhs_arena_dtor_registered, lhs, rhs_string,
rhs_arena, rhs_arena_dtor_registered, rhs);
if (unsafe_shallow_swap) {
ABSL_DCHECK_EQ(lhs_arena, rhs_arena);
InlinedStringField::InternalSwap(lhs_string, lhs_arena_dtor_registered, lhs,
rhs_string, rhs_arena_dtor_registered, rhs,
lhs_arena);
} else {
const std::string temp = lhs_string->Get();
lhs_string->Set(rhs_string->Get(), lhs_arena,
@ -697,7 +698,7 @@ void SwapFieldHelper::SwapArenaStringPtr(ArenaStringPtr* lhs, Arena* lhs_arena,
ArenaStringPtr* rhs,
Arena* rhs_arena) {
if (lhs_arena == rhs_arena) {
ArenaStringPtr::InternalSwap(lhs, lhs_arena, rhs, rhs_arena);
ArenaStringPtr::InternalSwap(lhs, rhs, lhs_arena);
} else if (lhs->IsDefault() && rhs->IsDefault()) {
// Nothing to do.
} else if (lhs->IsDefault()) {

@ -301,10 +301,10 @@ class PROTOBUF_EXPORT InlinedStringField {
// Swap()/UnsafeArenaSwap() at the message level, so this method is
// 'unsafe' if called directly.
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(
InlinedStringField* lhs, Arena* lhs_arena, bool lhs_arena_dtor_registered,
InlinedStringField* lhs, bool lhs_arena_dtor_registered,
MessageLite* lhs_msg, //
InlinedStringField* rhs, Arena* rhs_arena, bool rhs_arena_dtor_registered,
MessageLite* rhs_msg);
InlinedStringField* rhs, bool rhs_arena_dtor_registered,
MessageLite* rhs_msg, Arena* arena);
// Frees storage (if not on an arena).
PROTOBUF_NDEBUG_INLINE void Destroy(const std::string* default_value,
@ -407,22 +407,20 @@ inline void InlinedStringField::SetNoArena(std::string&& value) {
get_mutable()->assign(std::move(value));
}
// Caller should make sure rhs_arena allocated rhs, and lhs_arena allocated lhs.
inline PROTOBUF_NDEBUG_INLINE void InlinedStringField::InternalSwap(
InlinedStringField* lhs, Arena* lhs_arena, bool lhs_arena_dtor_registered,
InlinedStringField* lhs, bool lhs_arena_dtor_registered,
MessageLite* lhs_msg, //
InlinedStringField* rhs, Arena* rhs_arena, bool rhs_arena_dtor_registered,
MessageLite* rhs_msg) {
InlinedStringField* rhs, bool rhs_arena_dtor_registered,
MessageLite* rhs_msg, Arena* arena) {
#ifdef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE
lhs->get_mutable()->swap(*rhs->get_mutable());
if (!lhs_arena_dtor_registered && rhs_arena_dtor_registered) {
lhs_msg->OnDemandRegisterArenaDtor(lhs_arena);
lhs_msg->OnDemandRegisterArenaDtor(arena);
} else if (lhs_arena_dtor_registered && !rhs_arena_dtor_registered) {
rhs_msg->OnDemandRegisterArenaDtor(rhs_arena);
rhs_msg->OnDemandRegisterArenaDtor(arena);
}
#else
(void)lhs_arena;
(void)rhs_arena;
(void)arena;
(void)lhs_arena_dtor_registered;
(void)rhs_arena_dtor_registered;
(void)lhs_msg;

Loading…
Cancel
Save