Replace PROTOBUF_FORCE_COPY_IN_MOVE macro with constexpr function for easier

maintenance.
Also, added helper function to deduplicate the "can use fast swap" logic.
No semantic change expected.

PiperOrigin-RevId: 671837281
pull/18133/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent 5257fc6086
commit ad3222c124
  1. 10
      src/google/protobuf/arena.h
  2. 6
      src/google/protobuf/compiler/cpp/message.cc
  3. 6
      src/google/protobuf/compiler/java/java_features.pb.h
  4. 24
      src/google/protobuf/compiler/plugin.pb.h
  5. 6
      src/google/protobuf/cpp_features.pb.h
  6. 198
      src/google/protobuf/descriptor.pb.h
  7. 4
      src/google/protobuf/port.h
  8. 4
      src/google/protobuf/port_def.inc
  9. 1
      src/google/protobuf/port_undef.inc
  10. 25
      src/google/protobuf/repeated_field.h
  11. 20
      src/google/protobuf/repeated_ptr_field.h

@ -98,6 +98,16 @@ inline bool CanUseInternalSwap(Arena* lhs, Arena* rhs) {
} }
} }
inline bool CanMoveWithInternalSwap(Arena* lhs, Arena* rhs) {
if (DebugHardenForceCopyInMove()) {
// We force copy in move when we are not using an arena.
// If we did with an arena we would grow arena usage too much.
return lhs != nullptr && lhs == rhs;
} else {
return lhs == rhs;
}
}
} // namespace internal } // namespace internal
// ArenaOptions provides optional additional parameters to arena construction // ArenaOptions provides optional additional parameters to arena construction

@ -2085,11 +2085,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
} }
inline $classname$& operator=($classname$&& from) noexcept { inline $classname$& operator=($classname$&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if ($pbi$::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);

@ -118,11 +118,7 @@ class PROTOC_EXPORT JavaFeatures final
} }
inline JavaFeatures& operator=(JavaFeatures&& from) noexcept { inline JavaFeatures& operator=(JavaFeatures&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);

@ -135,11 +135,7 @@ class PROTOC_EXPORT Version final
} }
inline Version& operator=(Version&& from) noexcept { inline Version& operator=(Version&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -370,11 +366,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final
} }
inline CodeGeneratorResponse_File& operator=(CodeGeneratorResponse_File&& from) noexcept { inline CodeGeneratorResponse_File& operator=(CodeGeneratorResponse_File&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -621,11 +613,7 @@ class PROTOC_EXPORT CodeGeneratorResponse final
} }
inline CodeGeneratorResponse& operator=(CodeGeneratorResponse&& from) noexcept { inline CodeGeneratorResponse& operator=(CodeGeneratorResponse&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -896,11 +884,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final
} }
inline CodeGeneratorRequest& operator=(CodeGeneratorRequest&& from) noexcept { inline CodeGeneratorRequest& operator=(CodeGeneratorRequest&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);

@ -119,11 +119,7 @@ class PROTOBUF_EXPORT CppFeatures final
} }
inline CppFeatures& operator=(CppFeatures&& from) noexcept { inline CppFeatures& operator=(CppFeatures&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);

@ -721,11 +721,7 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final
} }
inline UninterpretedOption_NamePart& operator=(UninterpretedOption_NamePart&& from) noexcept { inline UninterpretedOption_NamePart& operator=(UninterpretedOption_NamePart&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -935,11 +931,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final
} }
inline SourceCodeInfo_Location& operator=(SourceCodeInfo_Location&& from) noexcept { inline SourceCodeInfo_Location& operator=(SourceCodeInfo_Location&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -1216,11 +1208,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final
} }
inline GeneratedCodeInfo_Annotation& operator=(GeneratedCodeInfo_Annotation&& from) noexcept { inline GeneratedCodeInfo_Annotation& operator=(GeneratedCodeInfo_Annotation&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -1492,11 +1480,7 @@ class PROTOBUF_EXPORT FieldOptions_FeatureSupport final
} }
inline FieldOptions_FeatureSupport& operator=(FieldOptions_FeatureSupport&& from) noexcept { inline FieldOptions_FeatureSupport& operator=(FieldOptions_FeatureSupport&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -1727,11 +1711,7 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final
} }
inline FieldOptions_EditionDefault& operator=(FieldOptions_EditionDefault&& from) noexcept { inline FieldOptions_EditionDefault& operator=(FieldOptions_EditionDefault&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -1936,11 +1916,7 @@ class PROTOBUF_EXPORT FeatureSet final
} }
inline FeatureSet& operator=(FeatureSet&& from) noexcept { inline FeatureSet& operator=(FeatureSet&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -2497,11 +2473,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final
} }
inline ExtensionRangeOptions_Declaration& operator=(ExtensionRangeOptions_Declaration&& from) noexcept { inline ExtensionRangeOptions_Declaration& operator=(ExtensionRangeOptions_Declaration&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -2751,11 +2723,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final
} }
inline EnumDescriptorProto_EnumReservedRange& operator=(EnumDescriptorProto_EnumReservedRange&& from) noexcept { inline EnumDescriptorProto_EnumReservedRange& operator=(EnumDescriptorProto_EnumReservedRange&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -2954,11 +2922,7 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final
} }
inline DescriptorProto_ReservedRange& operator=(DescriptorProto_ReservedRange&& from) noexcept { inline DescriptorProto_ReservedRange& operator=(DescriptorProto_ReservedRange&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -3157,11 +3121,7 @@ class PROTOBUF_EXPORT UninterpretedOption final
} }
inline UninterpretedOption& operator=(UninterpretedOption&& from) noexcept { inline UninterpretedOption& operator=(UninterpretedOption&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -3455,11 +3415,7 @@ class PROTOBUF_EXPORT SourceCodeInfo final
} }
inline SourceCodeInfo& operator=(SourceCodeInfo&& from) noexcept { inline SourceCodeInfo& operator=(SourceCodeInfo&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -3651,11 +3607,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final
} }
inline GeneratedCodeInfo& operator=(GeneratedCodeInfo&& from) noexcept { inline GeneratedCodeInfo& operator=(GeneratedCodeInfo&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -3847,11 +3799,7 @@ class PROTOBUF_EXPORT FeatureSetDefaults_FeatureSetEditionDefault final
} }
inline FeatureSetDefaults_FeatureSetEditionDefault& operator=(FeatureSetDefaults_FeatureSetEditionDefault&& from) noexcept { inline FeatureSetDefaults_FeatureSetEditionDefault& operator=(FeatureSetDefaults_FeatureSetEditionDefault&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -4076,11 +4024,7 @@ class PROTOBUF_EXPORT ServiceOptions final
} }
inline ServiceOptions& operator=(ServiceOptions&& from) noexcept { inline ServiceOptions& operator=(ServiceOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -4487,11 +4431,7 @@ class PROTOBUF_EXPORT OneofOptions final
} }
inline OneofOptions& operator=(OneofOptions&& from) noexcept { inline OneofOptions& operator=(OneofOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -4885,11 +4825,7 @@ class PROTOBUF_EXPORT MethodOptions final
} }
inline MethodOptions& operator=(MethodOptions&& from) noexcept { inline MethodOptions& operator=(MethodOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -5329,11 +5265,7 @@ class PROTOBUF_EXPORT MessageOptions final
} }
inline MessageOptions& operator=(MessageOptions&& from) noexcept { inline MessageOptions& operator=(MessageOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -5792,11 +5724,7 @@ class PROTOBUF_EXPORT FileOptions final
} }
inline FileOptions& operator=(FileOptions&& from) noexcept { inline FileOptions& operator=(FileOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -6517,11 +6445,7 @@ class PROTOBUF_EXPORT FieldOptions final
} }
inline FieldOptions& operator=(FieldOptions&& from) noexcept { inline FieldOptions& operator=(FieldOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -7178,11 +7102,7 @@ class PROTOBUF_EXPORT FeatureSetDefaults final
} }
inline FeatureSetDefaults& operator=(FeatureSetDefaults&& from) noexcept { inline FeatureSetDefaults& operator=(FeatureSetDefaults&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -7406,11 +7326,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final
} }
inline ExtensionRangeOptions& operator=(ExtensionRangeOptions&& from) noexcept { inline ExtensionRangeOptions& operator=(ExtensionRangeOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -7856,11 +7772,7 @@ class PROTOBUF_EXPORT EnumValueOptions final
} }
inline EnumValueOptions& operator=(EnumValueOptions&& from) noexcept { inline EnumValueOptions& operator=(EnumValueOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -8297,11 +8209,7 @@ class PROTOBUF_EXPORT EnumOptions final
} }
inline EnumOptions& operator=(EnumOptions&& from) noexcept { inline EnumOptions& operator=(EnumOptions&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -8734,11 +8642,7 @@ class PROTOBUF_EXPORT OneofDescriptorProto final
} }
inline OneofDescriptorProto& operator=(OneofDescriptorProto&& from) noexcept { inline OneofDescriptorProto& operator=(OneofDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -8952,11 +8856,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final
} }
inline MethodDescriptorProto& operator=(MethodDescriptorProto&& from) noexcept { inline MethodDescriptorProto& operator=(MethodDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -9234,11 +9134,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final
} }
inline FieldDescriptorProto& operator=(FieldDescriptorProto&& from) noexcept { inline FieldDescriptorProto& operator=(FieldDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -9648,11 +9544,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final
} }
inline EnumValueDescriptorProto& operator=(EnumValueDescriptorProto&& from) noexcept { inline EnumValueDescriptorProto& operator=(EnumValueDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -9879,11 +9771,7 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final
} }
inline DescriptorProto_ExtensionRange& operator=(DescriptorProto_ExtensionRange&& from) noexcept { inline DescriptorProto_ExtensionRange& operator=(DescriptorProto_ExtensionRange&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -10104,11 +9992,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final
} }
inline ServiceDescriptorProto& operator=(ServiceDescriptorProto&& from) noexcept { inline ServiceDescriptorProto& operator=(ServiceDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -10341,11 +10225,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto final
} }
inline EnumDescriptorProto& operator=(EnumDescriptorProto&& from) noexcept { inline EnumDescriptorProto& operator=(EnumDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -10622,11 +10502,7 @@ class PROTOBUF_EXPORT DescriptorProto final
} }
inline DescriptorProto& operator=(DescriptorProto&& from) noexcept { inline DescriptorProto& operator=(DescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -10999,11 +10875,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final
} }
inline FileDescriptorProto& operator=(FileDescriptorProto&& from) noexcept { inline FileDescriptorProto& operator=(FileDescriptorProto&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);
@ -11425,11 +11297,7 @@ class PROTOBUF_EXPORT FileDescriptorSet final
} }
inline FileDescriptorSet& operator=(FileDescriptorSet&& from) noexcept { inline FileDescriptorSet& operator=(FileDescriptorSet&& from) noexcept {
if (this == &from) return *this; if (this == &from) return *this;
if (GetArena() == from.GetArena() if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
&& GetArena() != nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
InternalSwap(&from); InternalSwap(&from);
} else { } else {
CopyFrom(from); CopyFrom(from);

@ -280,6 +280,10 @@ constexpr bool DebugHardenForceCopyInSwap() {
return false; return false;
} }
constexpr bool DebugHardenForceCopyInMove() {
return false;
}
// Returns true if pointers are 8B aligned, leaving least significant 3 bits // Returns true if pointers are 8B aligned, leaving least significant 3 bits
// available. // available.
inline constexpr bool PtrIsAtLeast8BAligned() { return alignof(void*) >= 8; } inline constexpr bool PtrIsAtLeast8BAligned() { return alignof(void*) >= 8; }

@ -398,10 +398,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#define PROTOBUF_RESTRICT #define PROTOBUF_RESTRICT
#endif #endif
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
#error PROTOBUF_FORCE_COPY_IN_MOVE was previously defined
#endif
#ifdef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG #ifdef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG
#error PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG was previously defined #error PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG was previously defined
#endif #endif

@ -41,7 +41,6 @@
#undef PROTOC_EXPORT #undef PROTOC_EXPORT
#undef PROTOBUF_NODISCARD #undef PROTOBUF_NODISCARD
#undef PROTOBUF_RESTRICT #undef PROTOBUF_RESTRICT
#undef PROTOBUF_FORCE_COPY_IN_MOVE
#undef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG #undef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG
#undef PROTOBUF_FORCE_COPY_DEFAULT_STRING #undef PROTOBUF_FORCE_COPY_DEFAULT_STRING
#undef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION #undef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION

@ -705,17 +705,13 @@ inline RepeatedField<Element>& RepeatedField<Element>::operator=(
template <typename Element> template <typename Element>
inline RepeatedField<Element>::RepeatedField(Arena* arena, RepeatedField&& rhs) inline RepeatedField<Element>::RepeatedField(Arena* arena, RepeatedField&& rhs)
: RepeatedField(arena) { : RepeatedField(arena) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE if (internal::CanMoveWithInternalSwap(arena, rhs.GetArena())) {
CopyFrom(rhs);
#else // PROTOBUF_FORCE_COPY_IN_MOVE
// We don't just call Swap(&rhs) here because it would perform 3 copies if rhs
// is on a different arena.
if (arena != rhs.GetArena()) {
CopyFrom(rhs);
} else {
InternalSwap(&rhs); InternalSwap(&rhs);
} else {
// We don't just call Swap(&rhs) here because it would perform 3 copies if
// rhs is on a different arena.
CopyFrom(rhs);
} }
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
} }
template <typename Element> template <typename Element>
@ -724,15 +720,10 @@ inline RepeatedField<Element>& RepeatedField<Element>::operator=(
// We don't just call Swap(&other) here because it would perform 3 copies if // We don't just call Swap(&other) here because it would perform 3 copies if
// the two fields are on different arenas. // the two fields are on different arenas.
if (this != &other) { if (this != &other) {
const Arena* arena = GetArena(); if (internal::CanMoveWithInternalSwap(GetArena(), other.GetArena())) {
if (arena != other.GetArena()
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
|| arena == nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
CopyFrom(other);
} else {
InternalSwap(&other); InternalSwap(&other);
} else {
CopyFrom(other);
} }
} }
return *this; return *this;

@ -1306,17 +1306,13 @@ template <typename Element>
inline RepeatedPtrField<Element>::RepeatedPtrField(Arena* arena, inline RepeatedPtrField<Element>::RepeatedPtrField(Arena* arena,
RepeatedPtrField&& rhs) RepeatedPtrField&& rhs)
: RepeatedPtrField(arena) { : RepeatedPtrField(arena) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
CopyFrom(rhs);
#else // PROTOBUF_FORCE_COPY_IN_MOVE
// We don't just call Swap(&rhs) here because it would perform 3 copies if rhs // We don't just call Swap(&rhs) here because it would perform 3 copies if rhs
// is on a different arena. // is on a different arena.
if (arena != rhs.GetArena()) { if (internal::CanMoveWithInternalSwap(arena, rhs.GetArena())) {
CopyFrom(rhs);
} else {
InternalSwap(&rhs); InternalSwap(&rhs);
} else {
CopyFrom(rhs);
} }
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
} }
template <typename Element> template <typename Element>
@ -1325,14 +1321,10 @@ inline RepeatedPtrField<Element>& RepeatedPtrField<Element>::operator=(
// We don't just call Swap(&other) here because it would perform 3 copies if // We don't just call Swap(&other) here because it would perform 3 copies if
// the two fields are on different arenas. // the two fields are on different arenas.
if (this != &other) { if (this != &other) {
if (GetArena() != other.GetArena() if (internal::CanMoveWithInternalSwap(GetArena(), other.GetArena())) {
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
|| GetArena() == nullptr
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
) {
CopyFrom(other);
} else {
InternalSwap(&other); InternalSwap(&other);
} else {
CopyFrom(other);
} }
} }
return *this; return *this;

Loading…
Cancel
Save