@@ -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
0 commit comments