Skip to content

Commit e8e3253

Browse files
zhangskzcopybara-github
authored andcommitted
Breaking Change: Remove deprecated RepeatedPtrField::ClearedCount().
These have been marked ABSL_DEPRECATED as of v4.22.x and was intended for removal in v5.26.x: https://protobuf.dev/news/2023-12-13/#remove-deprecated-clear-apis-on-repeated-fields. Users of this API should consider migrating to arenas for better memory reuse. See https://protobuf.dev/news/2024-10-02/#repeatedptrfieldclearedcount and https://protobuf.dev/support/migration/#cleared-elements PiperOrigin-RevId: 690652745
1 parent 24ef3d6 commit e8e3253

File tree

2 files changed

+0
-46
lines changed

2 files changed

+0
-46
lines changed

src/google/protobuf/repeated_ptr_field.h

-8
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,6 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase {
11461146
// Hardcore programs may choose to manipulate these cleared objects
11471147
// to better optimize memory management using the following routines.
11481148

1149-
// Gets the number of cleared objects that are currently being kept
1150-
// around for reuse.
1151-
ABSL_DEPRECATED("This will be removed in a future release")
1152-
int ClearedCount() const;
11531149

11541150
// Removes the element referenced by position.
11551151
//
@@ -1526,10 +1522,6 @@ inline Element* RepeatedPtrField<Element>::UnsafeArenaReleaseLast() {
15261522
return RepeatedPtrFieldBase::UnsafeArenaReleaseLast<TypeHandler>();
15271523
}
15281524

1529-
template <typename Element>
1530-
inline int RepeatedPtrField<Element>::ClearedCount() const {
1531-
return RepeatedPtrFieldBase::ClearedCount();
1532-
}
15331525

15341526
template <typename Element>
15351527
inline void RepeatedPtrField<Element>::Reserve(int new_size) {

src/google/protobuf/repeated_ptr_field_unittest.cc

-38
Original file line numberDiff line numberDiff line change
@@ -458,37 +458,6 @@ TEST(RepeatedPtrField, ReserveDoesntLoseAllocated) {
458458
EXPECT_EQ(first, field.Add());
459459
}
460460

461-
// Clearing elements is tricky with RepeatedPtrFields since the memory for
462-
// the elements is retained and reused.
463-
TEST(RepeatedPtrField, ClearedElements) {
464-
PROTOBUF_IGNORE_DEPRECATION_START
465-
RepeatedPtrField<std::string> field;
466-
467-
std::string* original = field.Add();
468-
*original = "foo";
469-
470-
EXPECT_EQ(field.ClearedCount(), 0);
471-
472-
field.RemoveLast();
473-
EXPECT_TRUE(original->empty());
474-
EXPECT_EQ(field.ClearedCount(), 1);
475-
476-
EXPECT_EQ(field.Add(),
477-
original); // Should return same string for reuse.
478-
EXPECT_EQ(field.UnsafeArenaReleaseLast(), original); // We take ownership.
479-
EXPECT_EQ(field.ClearedCount(), 0);
480-
481-
EXPECT_NE(field.Add(), original); // Should NOT return the same string.
482-
EXPECT_EQ(field.ClearedCount(), 0);
483-
484-
field.UnsafeArenaAddAllocated(original); // Give ownership back.
485-
EXPECT_EQ(field.ClearedCount(), 0);
486-
EXPECT_EQ(field.Mutable(1), original);
487-
488-
field.Clear();
489-
EXPECT_EQ(field.ClearedCount(), 2);
490-
PROTOBUF_IGNORE_DEPRECATION_STOP
491-
}
492461

493462
// Test all code paths in AddAllocated().
494463
TEST(RepeatedPtrField, AddAllocated) {
@@ -512,7 +481,6 @@ TEST(RepeatedPtrField, AddAllocated) {
512481
std::string* foo = new std::string("foo");
513482
field.AddAllocated(foo);
514483
EXPECT_EQ(index + 1, field.size());
515-
EXPECT_EQ(0, field.ClearedCount());
516484
EXPECT_EQ(foo, &field.Get(index));
517485

518486
// Last branch: Field is not at capacity and there are no cleared objects.
@@ -521,7 +489,6 @@ TEST(RepeatedPtrField, AddAllocated) {
521489
field.AddAllocated(bar);
522490
++index;
523491
EXPECT_EQ(index + 1, field.size());
524-
EXPECT_EQ(0, field.ClearedCount());
525492
EXPECT_EQ(bar, &field.Get(index));
526493

527494
// Third branch: Field is not at capacity and there are no cleared objects.
@@ -530,7 +497,6 @@ TEST(RepeatedPtrField, AddAllocated) {
530497
std::string* baz = new std::string("baz");
531498
field.AddAllocated(baz);
532499
EXPECT_EQ(index + 1, field.size());
533-
EXPECT_EQ(1, field.ClearedCount());
534500
EXPECT_EQ(baz, &field.Get(index));
535501

536502
// Second branch: Field is at capacity but has some cleared objects.
@@ -541,7 +507,6 @@ TEST(RepeatedPtrField, AddAllocated) {
541507
field.AddAllocated(moo);
542508
EXPECT_EQ(index + 1, field.size());
543509
// We should have discarded the cleared object.
544-
EXPECT_EQ(0, field.ClearedCount());
545510
EXPECT_EQ(moo, &field.Get(index));
546511
}
547512

@@ -937,7 +902,6 @@ TEST(RepeatedPtrField, ExtractSubrange) {
937902
EXPECT_EQ(field.size(), sz + extra);
938903
for (int i = 0; i < extra; ++i) field.RemoveLast();
939904
EXPECT_EQ(field.size(), sz);
940-
EXPECT_EQ(field.ClearedCount(), extra);
941905

942906
// Create a catcher array and call ExtractSubrange.
943907
std::string* catcher[10];
@@ -959,9 +923,7 @@ TEST(RepeatedPtrField, ExtractSubrange) {
959923
EXPECT_EQ(field.Mutable(i), subject[i + num]);
960924

961925
// Reinstate the cleared elements.
962-
EXPECT_EQ(field.ClearedCount(), extra);
963926
for (int i = 0; i < extra; ++i) field.Add();
964-
EXPECT_EQ(field.ClearedCount(), 0);
965927
EXPECT_EQ(field.size(), sz - num + extra);
966928

967929
// Make sure the extra elements are all there (in some order).

0 commit comments

Comments
 (0)