Remove `copy_to_from` from `ClassData`. It only ever has one useful value and

we can just hardcode that logic in `Message::CopyFrom`.
Also, move the implementation of `GetClassData` to the base class for zero field messages.

PiperOrigin-RevId: 563434532
pull/13897/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 0ed6737695
commit 7893dff9cd
  1. 66
      src/google/protobuf/compiler/cpp/message.cc
  2. 32
      src/google/protobuf/compiler/plugin.pb.cc
  3. 8
      src/google/protobuf/cpp_features.pb.cc
  4. 256
      src/google/protobuf/descriptor.pb.cc
  5. 5
      src/google/protobuf/generated_message_bases.cc
  6. 2
      src/google/protobuf/generated_message_bases.h
  7. 20
      src/google/protobuf/message.cc
  8. 3
      src/google/protobuf/message.h

@ -1616,7 +1616,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
"\n");
if (HasDescriptorMethods(descriptor_->file(), options_)) {
if (HasGeneratedMethods(descriptor_->file(), options_)) {
if (HasGeneratedMethods(descriptor_->file(), options_) &&
!HasSimpleBaseClass(descriptor_, options_)) {
format(
"static const ClassData _class_data_;\n"
"const ::$proto_ns$::Message::ClassData*"
@ -3928,48 +3929,33 @@ void MessageGenerator::GenerateSwap(io::Printer* p) {
void MessageGenerator::GenerateMergeFrom(io::Printer* p) {
Formatter format(p);
if (!HasSimpleBaseClass(descriptor_, options_)) {
if (HasDescriptorMethods(descriptor_->file(), options_)) {
// We don't override the generalized MergeFrom (aka that which
// takes in the Message base class as a parameter); instead we just
// let the base Message::MergeFrom take care of it. The base MergeFrom
// knows how to quickly confirm the types exactly match, and if so, will
// use GetClassData() to retrieve the address of MergeImpl, which calls
// the fast MergeFrom overload. Most callers avoid all this by passing
// a "from" message that is the same type as the message being merged
// into, rather than a generic Message.
if (HasSimpleBaseClass(descriptor_, options_)) return;
if (HasDescriptorMethods(descriptor_->file(), options_)) {
// We don't override the generalized MergeFrom (aka that which
// takes in the Message base class as a parameter); instead we just
// let the base Message::MergeFrom take care of it. The base MergeFrom
// knows how to quickly confirm the types exactly match, and if so, will
// use GetClassData() to retrieve the address of MergeImpl, which calls
// the fast MergeFrom overload. Most callers avoid all this by passing
// a "from" message that is the same type as the message being merged
// into, rather than a generic Message.
format(
"const ::$proto_ns$::Message::ClassData "
"$classname$::_class_data_ = {\n"
" ::$proto_ns$::Message::CopyWithSourceCheck,\n"
" $classname$::MergeImpl\n"
"};\n"
"const ::$proto_ns$::Message::ClassData*"
"$classname$::GetClassData() const { return &_class_data_; }\n"
"\n");
} else {
// Generate CheckTypeAndMergeFrom().
format(
"void $classname$::CheckTypeAndMergeFrom(\n"
" const ::$proto_ns$::MessageLite& from) {\n"
" MergeFrom(*::_pbi::DownCast<const $classname$*>(\n"
" &from));\n"
"}\n");
}
p->Emit(R"cc(
const ::$proto_ns$::Message::ClassData $classname$::_class_data_ = {
$classname$::MergeImpl,
};
const ::$proto_ns$::Message::ClassData* $classname$::GetClassData() const {
return &_class_data_;
}
)cc");
} else {
// In the simple case, we just define ClassData that vectors back to the
// simple implementation of Copy and Merge.
// Generate CheckTypeAndMergeFrom().
format(
"const ::$proto_ns$::Message::ClassData "
"$classname$::_class_data_ = {\n"
" $superclass$::CopyImpl,\n"
" $superclass$::MergeImpl,\n"
"};\n"
"const ::$proto_ns$::Message::ClassData*"
"$classname$::GetClassData() const { return &_class_data_; }\n"
"\n"
"\n");
"void $classname$::CheckTypeAndMergeFrom(\n"
" const ::$proto_ns$::MessageLite& from) {\n"
" MergeFrom(*::_pbi::DownCast<const $classname$*>(\n"
" &from));\n"
"}\n");
}
}

@ -542,11 +542,11 @@ const ::_pbi::TcParseTable<2, 4, 0, 47, 2> Version::_table_ = {
}
const ::google::protobuf::Message::ClassData Version::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
Version::MergeImpl
Version::MergeImpl,
};
const ::google::protobuf::Message::ClassData*Version::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* Version::GetClassData() const {
return &_class_data_;
}
void Version::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<Version*>(&to_msg);
@ -887,11 +887,11 @@ const ::_pbi::TcParseTable<3, 5, 3, 79, 2> CodeGeneratorRequest::_table_ = {
}
const ::google::protobuf::Message::ClassData CodeGeneratorRequest::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
CodeGeneratorRequest::MergeImpl
CodeGeneratorRequest::MergeImpl,
};
const ::google::protobuf::Message::ClassData*CodeGeneratorRequest::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* CodeGeneratorRequest::GetClassData() const {
return &_class_data_;
}
void CodeGeneratorRequest::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<CodeGeneratorRequest*>(&to_msg);
@ -1217,11 +1217,11 @@ const ::_pbi::TcParseTable<2, 4, 1, 86, 2> CodeGeneratorResponse_File::_table_ =
}
const ::google::protobuf::Message::ClassData CodeGeneratorResponse_File::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
CodeGeneratorResponse_File::MergeImpl
CodeGeneratorResponse_File::MergeImpl,
};
const ::google::protobuf::Message::ClassData*CodeGeneratorResponse_File::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* CodeGeneratorResponse_File::GetClassData() const {
return &_class_data_;
}
void CodeGeneratorResponse_File::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<CodeGeneratorResponse_File*>(&to_msg);
@ -1490,11 +1490,11 @@ const ::_pbi::TcParseTable<2, 3, 1, 60, 2> CodeGeneratorResponse::_table_ = {
}
const ::google::protobuf::Message::ClassData CodeGeneratorResponse::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
CodeGeneratorResponse::MergeImpl
CodeGeneratorResponse::MergeImpl,
};
const ::google::protobuf::Message::ClassData*CodeGeneratorResponse::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* CodeGeneratorResponse::GetClassData() const {
return &_class_data_;
}
void CodeGeneratorResponse::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<CodeGeneratorResponse*>(&to_msg);

@ -308,11 +308,11 @@ const ::_pbi::TcParseTable<1, 2, 1, 0, 2> CppFeatures::_table_ = {
}
const ::google::protobuf::Message::ClassData CppFeatures::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
CppFeatures::MergeImpl
CppFeatures::MergeImpl,
};
const ::google::protobuf::Message::ClassData*CppFeatures::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* CppFeatures::GetClassData() const {
return &_class_data_;
}
void CppFeatures::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<CppFeatures*>(&to_msg);

@ -2481,11 +2481,11 @@ constexpr ::_pbi::TcParseTable<0, 1, 1, 0, 2> FileDescriptorSet::_table_ = {
}
const ::google::protobuf::Message::ClassData FileDescriptorSet::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FileDescriptorSet::MergeImpl
FileDescriptorSet::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FileDescriptorSet::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FileDescriptorSet::GetClassData() const {
return &_class_data_;
}
void FileDescriptorSet::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FileDescriptorSet*>(&to_msg);
@ -3052,11 +3052,11 @@ constexpr ::_pbi::TcParseTable<4, 14, 7, 86, 2> FileDescriptorProto::_table_ = {
}
const ::google::protobuf::Message::ClassData FileDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FileDescriptorProto::MergeImpl
FileDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FileDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FileDescriptorProto::GetClassData() const {
return &_class_data_;
}
void FileDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FileDescriptorProto*>(&to_msg);
@ -3389,11 +3389,11 @@ constexpr ::_pbi::TcParseTable<2, 3, 1, 0, 2> DescriptorProto_ExtensionRange::_t
}
const ::google::protobuf::Message::ClassData DescriptorProto_ExtensionRange::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
DescriptorProto_ExtensionRange::MergeImpl
DescriptorProto_ExtensionRange::MergeImpl,
};
const ::google::protobuf::Message::ClassData*DescriptorProto_ExtensionRange::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* DescriptorProto_ExtensionRange::GetClassData() const {
return &_class_data_;
}
void DescriptorProto_ExtensionRange::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<DescriptorProto_ExtensionRange*>(&to_msg);
@ -3620,11 +3620,11 @@ constexpr ::_pbi::TcParseTable<1, 2, 0, 0, 2> DescriptorProto_ReservedRange::_ta
}
const ::google::protobuf::Message::ClassData DescriptorProto_ReservedRange::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
DescriptorProto_ReservedRange::MergeImpl
DescriptorProto_ReservedRange::MergeImpl,
};
const ::google::protobuf::Message::ClassData*DescriptorProto_ReservedRange::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* DescriptorProto_ReservedRange::GetClassData() const {
return &_class_data_;
}
void DescriptorProto_ReservedRange::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<DescriptorProto_ReservedRange*>(&to_msg);
@ -4071,11 +4071,11 @@ constexpr ::_pbi::TcParseTable<4, 10, 8, 65, 2> DescriptorProto::_table_ = {
}
const ::google::protobuf::Message::ClassData DescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
DescriptorProto::MergeImpl
DescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*DescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* DescriptorProto::GetClassData() const {
return &_class_data_;
}
void DescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<DescriptorProto*>(&to_msg);
@ -4439,11 +4439,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 0, 71, 2> ExtensionRangeOptions_Declaration
}
const ::google::protobuf::Message::ClassData ExtensionRangeOptions_Declaration::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
ExtensionRangeOptions_Declaration::MergeImpl
ExtensionRangeOptions_Declaration::MergeImpl,
};
const ::google::protobuf::Message::ClassData*ExtensionRangeOptions_Declaration::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* ExtensionRangeOptions_Declaration::GetClassData() const {
return &_class_data_;
}
void ExtensionRangeOptions_Declaration::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<ExtensionRangeOptions_Declaration*>(&to_msg);
@ -4763,11 +4763,11 @@ constexpr ::_pbi::TcParseTable<3, 4, 4, 0, 12> ExtensionRangeOptions::_table_ =
}
const ::google::protobuf::Message::ClassData ExtensionRangeOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
ExtensionRangeOptions::MergeImpl
ExtensionRangeOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*ExtensionRangeOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* ExtensionRangeOptions::GetClassData() const {
return &_class_data_;
}
void ExtensionRangeOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<ExtensionRangeOptions*>(&to_msg);
@ -5293,11 +5293,11 @@ constexpr ::_pbi::TcParseTable<4, 11, 3, 96, 2> FieldDescriptorProto::_table_ =
}
const ::google::protobuf::Message::ClassData FieldDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FieldDescriptorProto::MergeImpl
FieldDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FieldDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FieldDescriptorProto::GetClassData() const {
return &_class_data_;
}
void FieldDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FieldDescriptorProto*>(&to_msg);
@ -5592,11 +5592,11 @@ constexpr ::_pbi::TcParseTable<1, 2, 1, 49, 2> OneofDescriptorProto::_table_ = {
}
const ::google::protobuf::Message::ClassData OneofDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
OneofDescriptorProto::MergeImpl
OneofDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*OneofDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* OneofDescriptorProto::GetClassData() const {
return &_class_data_;
}
void OneofDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<OneofDescriptorProto*>(&to_msg);
@ -5818,11 +5818,11 @@ constexpr ::_pbi::TcParseTable<1, 2, 0, 0, 2> EnumDescriptorProto_EnumReservedRa
}
const ::google::protobuf::Message::ClassData EnumDescriptorProto_EnumReservedRange::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
EnumDescriptorProto_EnumReservedRange::MergeImpl
EnumDescriptorProto_EnumReservedRange::MergeImpl,
};
const ::google::protobuf::Message::ClassData*EnumDescriptorProto_EnumReservedRange::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* EnumDescriptorProto_EnumReservedRange::GetClassData() const {
return &_class_data_;
}
void EnumDescriptorProto_EnumReservedRange::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<EnumDescriptorProto_EnumReservedRange*>(&to_msg);
@ -6146,11 +6146,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 3, 61, 2> EnumDescriptorProto::_table_ = {
}
const ::google::protobuf::Message::ClassData EnumDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
EnumDescriptorProto::MergeImpl
EnumDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*EnumDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* EnumDescriptorProto::GetClassData() const {
return &_class_data_;
}
void EnumDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<EnumDescriptorProto*>(&to_msg);
@ -6441,11 +6441,11 @@ constexpr ::_pbi::TcParseTable<2, 3, 1, 53, 2> EnumValueDescriptorProto::_table_
}
const ::google::protobuf::Message::ClassData EnumValueDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
EnumValueDescriptorProto::MergeImpl
EnumValueDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*EnumValueDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* EnumValueDescriptorProto::GetClassData() const {
return &_class_data_;
}
void EnumValueDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<EnumValueDescriptorProto*>(&to_msg);
@ -6730,11 +6730,11 @@ constexpr ::_pbi::TcParseTable<2, 3, 2, 51, 2> ServiceDescriptorProto::_table_ =
}
const ::google::protobuf::Message::ClassData ServiceDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
ServiceDescriptorProto::MergeImpl
ServiceDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*ServiceDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* ServiceDescriptorProto::GetClassData() const {
return &_class_data_;
}
void ServiceDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<ServiceDescriptorProto*>(&to_msg);
@ -7109,11 +7109,11 @@ constexpr ::_pbi::TcParseTable<3, 6, 1, 71, 2> MethodDescriptorProto::_table_ =
}
const ::google::protobuf::Message::ClassData MethodDescriptorProto::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
MethodDescriptorProto::MergeImpl
MethodDescriptorProto::MergeImpl,
};
const ::google::protobuf::Message::ClassData*MethodDescriptorProto::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* MethodDescriptorProto::GetClassData() const {
return &_class_data_;
}
void MethodDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<MethodDescriptorProto*>(&to_msg);
@ -7938,11 +7938,11 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData FileOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FileOptions::MergeImpl
FileOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FileOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FileOptions::GetClassData() const {
return &_class_data_;
}
void FileOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FileOptions*>(&to_msg);
@ -8409,11 +8409,11 @@ constexpr ::_pbi::TcParseTable<3, 7, 2, 0, 7> MessageOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData MessageOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
MessageOptions::MergeImpl
MessageOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*MessageOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* MessageOptions::GetClassData() const {
return &_class_data_;
}
void MessageOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<MessageOptions*>(&to_msg);
@ -8707,11 +8707,11 @@ constexpr ::_pbi::TcParseTable<2, 3, 1, 64, 2> FieldOptions_EditionDefault::_tab
}
const ::google::protobuf::Message::ClassData FieldOptions_EditionDefault::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FieldOptions_EditionDefault::MergeImpl
FieldOptions_EditionDefault::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FieldOptions_EditionDefault::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FieldOptions_EditionDefault::GetClassData() const {
return &_class_data_;
}
void FieldOptions_EditionDefault::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FieldOptions_EditionDefault*>(&to_msg);
@ -9235,11 +9235,11 @@ constexpr ::_pbi::TcParseTable<4, 13, 7, 0, 7> FieldOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData FieldOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FieldOptions::MergeImpl
FieldOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FieldOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FieldOptions::GetClassData() const {
return &_class_data_;
}
void FieldOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FieldOptions*>(&to_msg);
@ -9535,11 +9535,11 @@ constexpr ::_pbi::TcParseTable<2, 2, 2, 0, 7> OneofOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData OneofOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
OneofOptions::MergeImpl
OneofOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*OneofOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* OneofOptions::GetClassData() const {
return &_class_data_;
}
void OneofOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<OneofOptions*>(&to_msg);
@ -9870,11 +9870,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 2, 0, 7> EnumOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData EnumOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
EnumOptions::MergeImpl
EnumOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*EnumOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* EnumOptions::GetClassData() const {
return &_class_data_;
}
void EnumOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<EnumOptions*>(&to_msg);
@ -10205,11 +10205,11 @@ constexpr ::_pbi::TcParseTable<3, 4, 2, 0, 7> EnumValueOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData EnumValueOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
EnumValueOptions::MergeImpl
EnumValueOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*EnumValueOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* EnumValueOptions::GetClassData() const {
return &_class_data_;
}
void EnumValueOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<EnumValueOptions*>(&to_msg);
@ -10506,11 +10506,11 @@ constexpr ::_pbi::TcParseTable<2, 3, 2, 0, 12> ServiceOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData ServiceOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
ServiceOptions::MergeImpl
ServiceOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*ServiceOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* ServiceOptions::GetClassData() const {
return &_class_data_;
}
void ServiceOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<ServiceOptions*>(&to_msg);
@ -10840,11 +10840,11 @@ constexpr ::_pbi::TcParseTable<3, 4, 3, 0, 12> MethodOptions::_table_ = {
}
const ::google::protobuf::Message::ClassData MethodOptions::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
MethodOptions::MergeImpl
MethodOptions::MergeImpl,
};
const ::google::protobuf::Message::ClassData*MethodOptions::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* MethodOptions::GetClassData() const {
return &_class_data_;
}
void MethodOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<MethodOptions*>(&to_msg);
@ -11098,11 +11098,11 @@ constexpr ::_pbi::TcParseTable<1, 2, 0, 62, 2> UninterpretedOption_NamePart::_ta
}
const ::google::protobuf::Message::ClassData UninterpretedOption_NamePart::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
UninterpretedOption_NamePart::MergeImpl
UninterpretedOption_NamePart::MergeImpl,
};
const ::google::protobuf::Message::ClassData*UninterpretedOption_NamePart::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* UninterpretedOption_NamePart::GetClassData() const {
return &_class_data_;
}
void UninterpretedOption_NamePart::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<UninterpretedOption_NamePart*>(&to_msg);
@ -11480,11 +11480,11 @@ constexpr ::_pbi::TcParseTable<3, 7, 1, 75, 2> UninterpretedOption::_table_ = {
}
const ::google::protobuf::Message::ClassData UninterpretedOption::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
UninterpretedOption::MergeImpl
UninterpretedOption::MergeImpl,
};
const ::google::protobuf::Message::ClassData*UninterpretedOption::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* UninterpretedOption::GetClassData() const {
return &_class_data_;
}
void UninterpretedOption::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<UninterpretedOption*>(&to_msg);
@ -11831,11 +11831,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 5, 0, 2> FeatureSet::_table_ = {
}
const ::google::protobuf::Message::ClassData FeatureSet::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FeatureSet::MergeImpl
FeatureSet::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FeatureSet::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FeatureSet::GetClassData() const {
return &_class_data_;
}
void FeatureSet::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FeatureSet*>(&to_msg);
@ -12129,11 +12129,11 @@ constexpr ::_pbi::TcParseTable<2, 3, 2, 75, 2> FeatureSetDefaults_FeatureSetEdit
}
const ::google::protobuf::Message::ClassData FeatureSetDefaults_FeatureSetEditionDefault::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl
FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FeatureSetDefaults_FeatureSetEditionDefault::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FeatureSetDefaults_FeatureSetEditionDefault::GetClassData() const {
return &_class_data_;
}
void FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FeatureSetDefaults_FeatureSetEditionDefault*>(&to_msg);
@ -12476,11 +12476,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 3, 73, 2> FeatureSetDefaults::_table_ = {
}
const ::google::protobuf::Message::ClassData FeatureSetDefaults::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
FeatureSetDefaults::MergeImpl
FeatureSetDefaults::MergeImpl,
};
const ::google::protobuf::Message::ClassData*FeatureSetDefaults::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* FeatureSetDefaults::GetClassData() const {
return &_class_data_;
}
void FeatureSetDefaults::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<FeatureSetDefaults*>(&to_msg);
@ -12832,11 +12832,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 0, 106, 2> SourceCodeInfo_Location::_table_
}
const ::google::protobuf::Message::ClassData SourceCodeInfo_Location::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
SourceCodeInfo_Location::MergeImpl
SourceCodeInfo_Location::MergeImpl,
};
const ::google::protobuf::Message::ClassData*SourceCodeInfo_Location::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* SourceCodeInfo_Location::GetClassData() const {
return &_class_data_;
}
void SourceCodeInfo_Location::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<SourceCodeInfo_Location*>(&to_msg);
@ -13032,11 +13032,11 @@ constexpr ::_pbi::TcParseTable<0, 1, 1, 0, 2> SourceCodeInfo::_table_ = {
}
const ::google::protobuf::Message::ClassData SourceCodeInfo::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
SourceCodeInfo::MergeImpl
SourceCodeInfo::MergeImpl,
};
const ::google::protobuf::Message::ClassData*SourceCodeInfo::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* SourceCodeInfo::GetClassData() const {
return &_class_data_;
}
void SourceCodeInfo::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<SourceCodeInfo*>(&to_msg);
@ -13352,11 +13352,11 @@ constexpr ::_pbi::TcParseTable<3, 5, 1, 64, 2> GeneratedCodeInfo_Annotation::_ta
}
const ::google::protobuf::Message::ClassData GeneratedCodeInfo_Annotation::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
GeneratedCodeInfo_Annotation::MergeImpl
GeneratedCodeInfo_Annotation::MergeImpl,
};
const ::google::protobuf::Message::ClassData*GeneratedCodeInfo_Annotation::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* GeneratedCodeInfo_Annotation::GetClassData() const {
return &_class_data_;
}
void GeneratedCodeInfo_Annotation::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<GeneratedCodeInfo_Annotation*>(&to_msg);
@ -13559,11 +13559,11 @@ constexpr ::_pbi::TcParseTable<0, 1, 1, 0, 2> GeneratedCodeInfo::_table_ = {
}
const ::google::protobuf::Message::ClassData GeneratedCodeInfo::_class_data_ = {
::google::protobuf::Message::CopyWithSourceCheck,
GeneratedCodeInfo::MergeImpl
GeneratedCodeInfo::MergeImpl,
};
const ::google::protobuf::Message::ClassData*GeneratedCodeInfo::GetClassData() const { return &_class_data_; }
const ::google::protobuf::Message::ClassData* GeneratedCodeInfo::GetClassData() const {
return &_class_data_;
}
void GeneratedCodeInfo::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
auto* const _this = static_cast<GeneratedCodeInfo*>(&to_msg);

@ -117,6 +117,11 @@ void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) {
_internal_metadata_.Swap<UnknownFieldSet>(&other->_internal_metadata_);
}
const Message::ClassData* ZeroFieldsBase::GetClassData() const {
static constexpr ClassData data = {&MergeImpl};
return &data;
}
} // namespace internal
} // namespace protobuf
} // namespace google

@ -72,6 +72,8 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message {
ZeroFieldsBase& operator=(const ZeroFieldsBase&) = delete;
~ZeroFieldsBase() override;
const ClassData* GetClassData() const final;
static void MergeImpl(Message& to, const Message& from);
static void CopyImpl(Message& to, const Message& from);
void InternalSwap(ZeroFieldsBase* other);

@ -102,9 +102,14 @@ void Message::CopyFrom(const Message& from) {
auto* class_to = GetClassData();
auto* class_from = from.GetClassData();
auto* copy_to_from = class_to ? class_to->copy_to_from : nullptr;
if (class_to == nullptr || class_to != class_from) {
if (class_from != nullptr && class_from == class_to) {
// Fail if "from" is a descendant of "to" as such copy is not allowed.
ABSL_DCHECK(!internal::IsDescendant(*this, from))
<< "Source of CopyFrom cannot be a descendant of the target.";
Clear();
class_to->merge_to_from(*this, from);
} else {
const Descriptor* descriptor = GetDescriptor();
ABSL_CHECK_EQ(from.GetDescriptor(), descriptor)
<< ": Tried to copy from a message with a different type. "
@ -113,20 +118,11 @@ void Message::CopyFrom(const Message& from) {
<< ", "
"from: "
<< from.GetDescriptor()->full_name();
copy_to_from = [](Message& to, const Message& from) {
ReflectionOps::Copy(from, &to);
};
ReflectionOps::Copy(from, this);
}
copy_to_from(*this, from);
}
void Message::CopyWithSourceCheck(Message& to, const Message& from) {
// Fail if "from" is a descendant of "to" as such copy is not allowed.
ABSL_DCHECK(!internal::IsDescendant(to, from))
<< "Source of CopyFrom cannot be a descendant of the target.";
to.Clear();
to.GetClassData()->merge_to_from(to, from);
}
std::string Message::GetTypeName() const {

@ -387,9 +387,8 @@ class PROTOBUF_EXPORT Message : public MessageLite {
struct ClassData {
// Note: The order of arguments (to, then from) is chosen so that the ABI
// of this function is the same as the CopyFrom method. That is, the
// of this function is the same as the MergeFrom method. That is, the
// hidden "this" parameter comes first.
void (*copy_to_from)(Message& to, const Message& from_msg);
void (*merge_to_from)(Message& to, const Message& from_msg);
};
// GetClassData() returns a pointer to a ClassData struct which

Loading…
Cancel
Save