Outline `RepeatedPtrFieldBase::SwapFallback`.
PiperOrigin-RevId: 805961375
diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h
index 952751f..b34959d 100644
--- a/src/google/protobuf/repeated_ptr_field.h
+++ b/src/google/protobuf/repeated_ptr_field.h
@@ -553,23 +553,11 @@
UnsafeArenaAddAllocated<H>(value);
}
+ // TODO - Outline this function so a future change can use a
+ // type in its implementation that requires `RepeatedPtrFieldBase` to be fully
+ // defined.
template <typename TypeHandler>
- PROTOBUF_NOINLINE void SwapFallback(RepeatedPtrFieldBase* other) {
- ABSL_DCHECK(!internal::CanUseInternalSwap(GetArena(), other->GetArena()));
-
- // Copy semantics in this case. We try to improve efficiency by placing the
- // temporary on |other|'s arena so that messages are copied twice rather
- // than three times.
- RepeatedPtrFieldBase temp(other->GetArena());
- if (!this->empty()) {
- temp.MergeFrom<typename TypeHandler::Type>(*this);
- }
- this->CopyFrom<TypeHandler>(*other);
- other->InternalSwap(&temp);
- if (temp.NeedsDestroy()) {
- temp.Destroy<TypeHandler>();
- }
- }
+ PROTOBUF_NOINLINE void SwapFallback(RepeatedPtrFieldBase* other);
// Gets the Arena on which this RepeatedPtrField stores its elements.
inline Arena* GetArena() const { return arena_; }
@@ -837,6 +825,25 @@
return result;
}
+template <typename TypeHandler>
+PROTOBUF_NOINLINE void RepeatedPtrFieldBase::SwapFallback(
+ RepeatedPtrFieldBase* other) {
+ ABSL_DCHECK(!internal::CanUseInternalSwap(GetArena(), other->GetArena()));
+
+ // Copy semantics in this case. We try to improve efficiency by placing the
+ // temporary on |other|'s arena so that messages are copied twice rather
+ // than three times.
+ RepeatedPtrFieldBase temp(other->GetArena());
+ if (!this->empty()) {
+ temp.MergeFrom<typename TypeHandler::Type>(*this);
+ }
+ this->CopyFrom<TypeHandler>(*other);
+ other->InternalSwap(&temp);
+ if (temp.NeedsDestroy()) {
+ temp.Destroy<TypeHandler>();
+ }
+}
+
PROTOBUF_EXPORT void InternalOutOfLineDeleteMessageLite(MessageLite* message);
// Encapsulates the minimally required subset of T's properties in a