Skip to content

Commit 514c9a8

Browse files
Breaking change: Make RepeatedField::GetArena non-const in order to support split RepeatedFields.
PiperOrigin-RevId: 503205991
1 parent 58f6216 commit 514c9a8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/google/protobuf/arena.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
394394
// time. Note that we can often devirtualize calls to `value->GetArena()` so
395395
// usually calling this method is unnecessary.
396396
template <typename T>
397-
PROTOBUF_ALWAYS_INLINE static Arena* GetArena(const T* value) {
397+
PROTOBUF_ALWAYS_INLINE static Arena* GetArena(T* value) {
398398
return GetArenaInternal(value);
399399
}
400400

@@ -432,31 +432,31 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
432432

433433
static void InternalSwap(T* a, T* b) { a->InternalSwap(b); }
434434

435-
static Arena* GetArenaForAllocation(const T* p) {
435+
static Arena* GetArenaForAllocation(T* p) {
436436
return GetArenaForAllocation(Rank0{}, p);
437437
}
438438

439-
static Arena* GetArena(const T* p) {
439+
static Arena* GetArena(T* p) {
440440
// Rather than replicate probing for `GetArena` with fallback to nullptr,
441441
// we borrow the implementation of `GetArenaForAllocation` but skip
442442
// `Rank0` which probes for `GetArenaForAllocation`.
443443
return GetArenaForAllocation(Rank1{}, p);
444444
}
445445

446446
template <typename U>
447-
static auto GetArenaForAllocation(Rank0, const U* p)
447+
static auto GetArenaForAllocation(Rank0, U* p)
448448
-> EnableIfArena<decltype(p->GetArenaForAllocation())> {
449449
return p->GetArenaForAllocation();
450450
}
451451

452452
template <typename U>
453-
static auto GetArenaForAllocation(Rank1, const U* p)
453+
static auto GetArenaForAllocation(Rank1, U* p)
454454
-> EnableIfArena<decltype(p->GetArena())> {
455455
return p->GetArena();
456456
}
457457

458458
template <typename U>
459-
static Arena* GetArenaForAllocation(Rank2, const U*) {
459+
static Arena* GetArenaForAllocation(Rank2, U*) {
460460
return nullptr;
461461
}
462462

@@ -506,7 +506,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
506506
// Provides access to protected GetArenaForAllocation to generated messages.
507507
// For internal use only.
508508
template <typename T>
509-
static Arena* InternalGetArenaForAllocation(const T* p) {
509+
static Arena* InternalGetArenaForAllocation(T* p) {
510510
return InternalHelper<T>::GetArenaForAllocation(p);
511511
}
512512

@@ -650,7 +650,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
650650
// InternalArenaConstructable_ tags can be associated with an arena, and such
651651
// objects must implement a GetArena() method.
652652
template <typename T>
653-
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
653+
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(T* value) {
654654
return InternalHelper<T>::GetArena(value);
655655
}
656656

src/google/protobuf/repeated_field.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ class RepeatedField final {
310310
iterator erase(const_iterator first, const_iterator last);
311311

312312
// Gets the Arena on which this RepeatedField stores its elements.
313-
inline Arena* GetArena() const { return GetOwningArena(); }
313+
// Note: this can be inaccurate for split default fields so we make this
314+
// function non-const.
315+
inline Arena* GetArena() { return GetOwningArena(); }
314316

315317
// For internal use only.
316318
//

0 commit comments

Comments
 (0)