diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index d47404e7c6..010b7582ef 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.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 - 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 - static auto GetArenaForAllocation(Rank0, const U* p) + static auto GetArenaForAllocation(Rank0, U* p) -> EnableIfArenaGetArenaForAllocation())> { return p->GetArenaForAllocation(); } template - static auto GetArenaForAllocation(Rank1, const U* p) + static auto GetArenaForAllocation(Rank1, U* p) -> EnableIfArenaGetArena())> { return p->GetArena(); } template - 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 - static Arena* InternalGetArenaForAllocation(const T* p) { + static Arena* InternalGetArenaForAllocation(T* p) { return InternalHelper::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 - PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { + PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(T* value) { return InternalHelper::GetArena(value); } diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 3353761a43..02e5166319 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -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. //