Breaking change: Make RepeatedField::GetArena non-const in order to support split RepeatedFields.

PiperOrigin-RevId: 503205991
pull/11598/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 58f6216d8d
commit 514c9a8e2a
  1. 16
      src/google/protobuf/arena.h
  2. 4
      src/google/protobuf/repeated_field.h

@ -394,7 +394,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// time. Note that we can often devirtualize calls to `value->GetArena()` so
// usually calling this method is unnecessary.
template <typename T>
PROTOBUF_ALWAYS_INLINE static Arena* GetArena(const T* value) {
PROTOBUF_ALWAYS_INLINE static Arena* GetArena(T* value) {
return GetArenaInternal(value);
}
@ -432,11 +432,11 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
static void InternalSwap(T* a, T* b) { a->InternalSwap(b); }
static Arena* GetArenaForAllocation(const T* p) {
static Arena* GetArenaForAllocation(T* p) {
return GetArenaForAllocation(Rank0{}, p);
}
static Arena* GetArena(const T* p) {
static Arena* GetArena(T* p) {
// Rather than replicate probing for `GetArena` with fallback to nullptr,
// we borrow the implementation of `GetArenaForAllocation` but skip
// `Rank0` which probes for `GetArenaForAllocation`.
@ -444,19 +444,19 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
}
template <typename U>
static auto GetArenaForAllocation(Rank0, const U* p)
static auto GetArenaForAllocation(Rank0, U* p)
-> EnableIfArena<decltype(p->GetArenaForAllocation())> {
return p->GetArenaForAllocation();
}
template <typename U>
static auto GetArenaForAllocation(Rank1, const U* p)
static auto GetArenaForAllocation(Rank1, U* p)
-> EnableIfArena<decltype(p->GetArena())> {
return p->GetArena();
}
template <typename U>
static Arena* GetArenaForAllocation(Rank2, const U*) {
static Arena* GetArenaForAllocation(Rank2, U*) {
return nullptr;
}
@ -506,7 +506,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// Provides access to protected GetArenaForAllocation to generated messages.
// For internal use only.
template <typename T>
static Arena* InternalGetArenaForAllocation(const T* p) {
static Arena* InternalGetArenaForAllocation(T* p) {
return InternalHelper<T>::GetArenaForAllocation(p);
}
@ -650,7 +650,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
// InternalArenaConstructable_ tags can be associated with an arena, and such
// objects must implement a GetArena() method.
template <typename T>
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(T* value) {
return InternalHelper<T>::GetArena(value);
}

@ -310,7 +310,9 @@ class RepeatedField final {
iterator erase(const_iterator first, const_iterator last);
// Gets the Arena on which this RepeatedField stores its elements.
inline Arena* GetArena() const { return GetOwningArena(); }
// Note: this can be inaccurate for split default fields so we make this
// function non-const.
inline Arena* GetArena() { return GetOwningArena(); }
// For internal use only.
//

Loading…
Cancel
Save