Skip to content

Commit 365ae12

Browse files
Internal change
PiperOrigin-RevId: 731380026
1 parent 74bf391 commit 365ae12

File tree

6 files changed

+0
-238
lines changed

6 files changed

+0
-238
lines changed

src/google/protobuf/extension_set.cc

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,131 +1402,6 @@ size_t ExtensionSet::ByteSize() const {
14021402
return total_size;
14031403
}
14041404

1405-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
1406-
size_t ExtensionSet::ByteSizeV2() const {
1407-
static constexpr int8_t kFieldSizes[] = {
1408-
-1,
1409-
sizeof(double), // TYPE_DOUBLE
1410-
sizeof(float), // TYPE_FLOAT
1411-
sizeof(int64_t), // TYPE_INT64
1412-
sizeof(uint64_t), // TYPE_UINT64
1413-
sizeof(int32_t), // TYPE_INT32
1414-
sizeof(uint64_t), // TYPE_FIXED64
1415-
sizeof(uint32_t), // TYPE_FIXED32
1416-
sizeof(bool), // TYPE_BOOL
1417-
-1, // TYPE_STRING
1418-
-1, // TYPE_GROUP
1419-
-1, // TYPE_MESSAGE
1420-
-1, // TYPE_BYTES
1421-
sizeof(uint32_t), // TYPE_UINT32
1422-
sizeof(int), // TYPE_ENUM
1423-
sizeof(uint32_t), // TYPE_SFIXED32
1424-
sizeof(uint64_t), // TYPE_SFIXED64
1425-
sizeof(int32_t), // TYPE_SINT32
1426-
sizeof(int64_t), // TYPE_SINT64
1427-
};
1428-
1429-
size_t total_size = 0;
1430-
ForEach(
1431-
[&total_size](int /* number */, const ExtensionSet::Extension& ext) {
1432-
// We assume that (singular) message extensions are common cases.
1433-
if (ABSL_PREDICT_TRUE(ext.type == WireFormatLite::TYPE_MESSAGE ||
1434-
ext.type == WireFormatLite::TYPE_GROUP)) {
1435-
if (ABSL_PREDICT_FALSE(ext.is_repeated)) {
1436-
const auto* rep = ext.ptr.repeated_message_value;
1437-
if (rep->empty()) return;
1438-
size_t size = 0;
1439-
for (const auto& each : *rep) {
1440-
size += each.ByteSizeV2();
1441-
}
1442-
total_size += v2::kRepeatedFieldTagSize +
1443-
v2::kLengthSize * rep->size() + size;
1444-
} else if (ABSL_PREDICT_TRUE(ext.is_lazy)) {
1445-
total_size += std::visit(
1446-
absl::Overload{
1447-
[&](const MessageLite* ptr) {
1448-
return WireFormatLite::LengthPrefixedByteSizeV2(
1449-
ptr->ByteSizeV2());
1450-
},
1451-
[](size_t unparsed_size) {
1452-
return WireFormatLite::LengthPrefixedByteSizeV2(
1453-
unparsed_size);
1454-
}},
1455-
ext.ptr.lazymessage_value->UnparsedSizeOrMessage());
1456-
} else {
1457-
total_size += WireFormatLite::LengthPrefixedByteSizeV2(
1458-
ext.ptr.message_value->ByteSizeV2());
1459-
}
1460-
return;
1461-
}
1462-
1463-
// Handle string fields as numerics are fixed widths.
1464-
if (ext.type == WireFormatLite::TYPE_STRING ||
1465-
ext.type == WireFormatLite::TYPE_BYTES) {
1466-
if (ext.is_repeated) {
1467-
total_size += WireFormatLite::RepeatedStringByteSizeV2(
1468-
*ext.ptr.repeated_string_value);
1469-
} else {
1470-
total_size += WireFormatLite::LengthPrefixedByteSizeV2(
1471-
ext.ptr.string_value->size());
1472-
}
1473-
return;
1474-
}
1475-
1476-
// The rest of the types are numeric fields with fixed widths for v2.
1477-
if (ext.is_repeated) {
1478-
switch (ext.type) {
1479-
case WireFormatLite::TYPE_DOUBLE:
1480-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1481-
*ext.ptr.repeated_double_value);
1482-
break;
1483-
case WireFormatLite::TYPE_FLOAT:
1484-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1485-
*ext.ptr.repeated_float_value);
1486-
break;
1487-
case WireFormatLite::TYPE_ENUM:
1488-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1489-
*ext.ptr.repeated_enum_value);
1490-
break;
1491-
case WireFormatLite::TYPE_INT32:
1492-
case WireFormatLite::TYPE_SFIXED32:
1493-
case WireFormatLite::TYPE_SINT32:
1494-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1495-
*ext.ptr.repeated_int32_t_value);
1496-
break;
1497-
case WireFormatLite::TYPE_INT64:
1498-
case WireFormatLite::TYPE_SFIXED64:
1499-
case WireFormatLite::TYPE_SINT64:
1500-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1501-
*ext.ptr.repeated_int64_t_value);
1502-
break;
1503-
case WireFormatLite::TYPE_FIXED32:
1504-
case WireFormatLite::TYPE_UINT32:
1505-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1506-
*ext.ptr.repeated_uint32_t_value);
1507-
break;
1508-
case WireFormatLite::TYPE_FIXED64:
1509-
case WireFormatLite::TYPE_UINT64:
1510-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1511-
*ext.ptr.repeated_uint64_t_value);
1512-
break;
1513-
case WireFormatLite::TYPE_BOOL:
1514-
total_size += WireFormatLite::RepeatedNumericByteSizeV2(
1515-
*ext.ptr.repeated_bool_value);
1516-
break;
1517-
default:
1518-
Unreachable();
1519-
}
1520-
} else {
1521-
auto field_size = kFieldSizes[ext.type];
1522-
ABSL_DCHECK_NE(field_size, -1);
1523-
total_size += v2::kSingularFieldTagSize + field_size;
1524-
}
1525-
},
1526-
ExtensionSet::Prefetch{});
1527-
return total_size;
1528-
}
1529-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
15301405

15311406
// Defined in extension_set_heavy.cc.
15321407
// int ExtensionSet::SpaceUsedExcludingSelf() const

src/google/protobuf/extension_set.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,6 @@ class PROTOBUF_EXPORT ExtensionSet {
531531

532532
// Returns the total serialized size of all the extensions.
533533
size_t ByteSize() const;
534-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
535-
size_t ByteSizeV2() const;
536-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
537534

538535
// Like ByteSize() but uses MessageSet format.
539536
size_t MessageSetByteSize() const;
@@ -672,10 +669,6 @@ class PROTOBUF_EXPORT ExtensionSet {
672669
const MessageLite* prototype, int number, uint8_t* target,
673670
io::EpsCopyOutputStream* stream) const = 0;
674671

675-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
676-
virtual size_t ByteSizeLongV2() const = 0;
677-
virtual uint8_t* WriteMessageToArrayV2(uint8_t* target) const = 0;
678-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
679672

680673
private:
681674
virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable.

src/google/protobuf/generated_message_bases.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ size_t ZeroFieldsBase::ByteSizeLong(const MessageLite& base) {
4848
return msg.MaybeComputeUnknownFieldsSize(0, &msg._impl_._cached_size_);
4949
}
5050

51-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
52-
size_t ZeroFieldsBase::ByteSizeV2Impl(const MessageLite& base) {
53-
auto& msg = static_cast<const ZeroFieldsBase&>(base);
54-
return msg.MaybeComputeUnknownFieldsSize(v2::kPoisonV2HeaderSize,
55-
&msg._impl_._cached_size_);
56-
}
57-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
5851

5952
::uint8_t* ZeroFieldsBase::_InternalSerialize(const MessageLite& msg,
6053
::uint8_t* target,

src/google/protobuf/generated_message_bases.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message {
3333
public:
3434
ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL { Clear(*this); }
3535
size_t ByteSizeLong() const PROTOBUF_FINAL { return ByteSizeLong(*this); }
36-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
37-
size_t ByteSizeV2() const { return ByteSizeV2Impl(*this); }
38-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
3936
int GetCachedSize() const { return _impl_._cached_size_.Get(); }
4037
::uint8_t* _InternalSerialize(
4138
::uint8_t* target, io::EpsCopyOutputStream* stream) const PROTOBUF_FINAL {
@@ -52,11 +49,6 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message {
5249
void InternalSwap(ZeroFieldsBase* other);
5350
static void Clear(MessageLite& msg);
5451
static size_t ByteSizeLong(const MessageLite& base);
55-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
56-
static size_t ByteSizeV2Impl(const MessageLite& base);
57-
58-
static constexpr auto& _v2_table_ = v2::kEmptyMessageTable;
59-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
6052
static ::uint8_t* _InternalSerialize(const MessageLite& msg,
6153
::uint8_t* target,
6254
io::EpsCopyOutputStream* stream);

src/google/protobuf/message_lite.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,6 @@ struct PROTOBUF_EXPORT ClassData {
367367
// char[] just beyond the ClassData.
368368
bool is_lite;
369369
bool is_dynamic = false;
370-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
371-
const void* v2_message_table = nullptr;
372-
const void* v2_parse_table = nullptr;
373-
size_t (*byte_size_v2)(const MessageLite&) = nullptr;
374-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
375370

376371
// In normal mode we have the small constructor to avoid the cost in
377372
// codegen.
@@ -383,12 +378,6 @@ struct PROTOBUF_EXPORT ClassData {
383378
void (*merge_to_from)(MessageLite& to, const MessageLite& from_msg),
384379
internal::MessageCreator message_creator, uint32_t cached_size_offset,
385380
bool is_lite
386-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
387-
,
388-
const void* v2_message_table = nullptr,
389-
const void* v2_parse_table = nullptr,
390-
size_t (*byte_size_v2)(const MessageLite&) = nullptr
391-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
392381
)
393382
: prototype(prototype),
394383
tc_table(tc_table),
@@ -398,12 +387,6 @@ struct PROTOBUF_EXPORT ClassData {
398387
message_creator(message_creator),
399388
cached_size_offset(cached_size_offset),
400389
is_lite(is_lite)
401-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
402-
,
403-
v2_message_table(v2_message_table),
404-
v2_parse_table(v2_parse_table),
405-
byte_size_v2(byte_size_v2)
406-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
407390
{
408391
}
409392
#endif // !PROTOBUF_CUSTOM_VTABLE
@@ -422,12 +405,6 @@ struct PROTOBUF_EXPORT ClassData {
422405
uint8_t* (*serialize)(const MessageLite& msg, uint8_t* ptr,
423406
io::EpsCopyOutputStream* stream),
424407
uint32_t cached_size_offset, bool is_lite
425-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
426-
,
427-
const void* v2_message_table = nullptr,
428-
const void* v2_parse_table = nullptr,
429-
size_t (*byte_size_v2)(const MessageLite&) = nullptr
430-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
431408
)
432409
: prototype(prototype),
433410
tc_table(tc_table),
@@ -443,12 +420,6 @@ struct PROTOBUF_EXPORT ClassData {
443420
#endif // PROTOBUF_CUSTOM_VTABLE
444421
cached_size_offset(cached_size_offset),
445422
is_lite(is_lite)
446-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
447-
,
448-
v2_message_table(v2_message_table),
449-
v2_parse_table(v2_parse_table),
450-
byte_size_v2(byte_size_v2)
451-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
452423
{
453424
}
454425

@@ -849,9 +820,6 @@ class PROTOBUF_EXPORT MessageLite {
849820
virtual size_t ByteSizeLong() const = 0;
850821
#endif // PROTOBUF_CUSTOM_VTABLE
851822

852-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
853-
size_t ByteSizeV2() const { return GetClassData()->byte_size_v2(*this); }
854-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
855823

856824
// Legacy ByteSize() API.
857825
[[deprecated("Please use ByteSizeLong() instead")]] int ByteSize() const {
@@ -967,26 +935,6 @@ class PROTOBUF_EXPORT MessageLite {
967935
return tc_table;
968936
}
969937

970-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
971-
// TODO: b/393403510 - For now, we return a void* to avoid taking a dependency
972-
// to the V2 parse table header. This will require an additional
973-
// reinterpret_cast in the V2 parse loop. When we start feeling confident in
974-
// the V2 implementation, we can work on making this function return the
975-
// proper type (should be internal::v2::ParseTableBase*).
976-
const void* GetV2ParseTable() const {
977-
auto* data = GetClassData();
978-
ABSL_DCHECK_NE(data, nullptr);
979-
980-
auto* table = data->v2_parse_table;
981-
// TODO: b/393403284 - The V1 implementation has a descriptor method that
982-
// can get the parse table for dynamic messages:
983-
// http://google3/third_party/protobuf/message_lite.h;l=490;rcl=718025165
984-
//
985-
// Eventually, we should also support that for V2 parse.
986-
ABSL_DCHECK_NE(table, nullptr);
987-
return table;
988-
}
989-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
990938

991939
#if defined(PROTOBUF_CUSTOM_VTABLE)
992940
explicit constexpr MessageLite(const internal::ClassData* data)

src/google/protobuf/wire_format_lite.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -760,45 +760,6 @@ class PROTOBUF_EXPORT WireFormatLite {
760760
// wire if we encode the data as a length delimited field.
761761
static inline size_t LengthDelimitedSize(size_t length);
762762

763-
#ifdef PROTOBUF_INTERNAL_V2_EXPERIMENT
764-
// v2 wireformat helpers for ByteSize.
765-
template <typename T>
766-
static size_t RepeatedNumericByteSizeV2(const RepeatedField<T>& value) {
767-
return value.empty() ? 0
768-
: v2::kRepeatedFieldTagSize + value.size() * sizeof(T);
769-
}
770-
771-
template <typename RepeatedT>
772-
static size_t RepeatedStringByteSizeV2(const RepeatedT& value) {
773-
if (value.empty()) return 0;
774-
775-
size_t total_bytes = 0;
776-
for (const auto& each : value) {
777-
total_bytes += each.size();
778-
}
779-
// Add size for length (sizeof(uint32_t)) per element.
780-
return v2::kRepeatedFieldTagSize + v2::kLengthSize * value.size() +
781-
total_bytes;
782-
}
783-
784-
template <typename RepeatedT>
785-
static size_t RepeatedMessageByteSizeV2(const RepeatedT& value) {
786-
if (value.empty()) return 0;
787-
788-
size_t total_bytes = 0;
789-
for (const auto& each : value) {
790-
total_bytes += each.ByteSizeV2();
791-
}
792-
// Add size for length (sizeof(uint32_t)) per element.
793-
return v2::kRepeatedFieldTagSize + v2::kLengthSize * value.size() +
794-
total_bytes;
795-
}
796-
797-
static inline size_t LengthPrefixedByteSizeV2(size_t field_size) {
798-
// <tag> <field_number> <length> <payload>
799-
return v2::kSingularFieldTagSize + v2::kLengthSize + field_size;
800-
}
801-
#endif // PROTOBUF_INTERNAL_V2_EXPERIMENT
802763

803764
private:
804765
// A helper method for the repeated primitive reader. This method has

0 commit comments

Comments
 (0)