Skip to content

Commit 75afd7f

Browse files
ClaytonKnittelcopybara-github
authored andcommitted
Enable fast-path parsing for repeated Cord fields.
PiperOrigin-RevId: 792758858
1 parent 6753056 commit 75afd7f

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

src/google/protobuf/generated_message_tctable_gen.cc

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ TailCallTableInfo::FastFieldInfo::Field MakeFastFieldEntry(
151151

152152
#define PROTOBUF_PICK_STRING_FUNCTION(fn) \
153153
(field->cpp_string_type() == FieldDescriptor::CppStringType::kCord \
154-
? PROTOBUF_PICK_FUNCTION(fn##cS) \
154+
? PROTOBUF_PICK_REPEATABLE_FUNCTION(fn##c) \
155155
: field->cpp_string_type() == FieldDescriptor::CppStringType::kView && \
156156
options.use_micro_string \
157157
? PROTOBUF_PICK_FUNCTION(fn##mS) \
@@ -739,27 +739,6 @@ bool IsFieldTypeEligibleForFastParsing(const FieldDescriptor* field) {
739739
return false;
740740
}
741741

742-
switch (field->type()) {
743-
// Some bytes fields can be handled on fast path.
744-
case FieldDescriptor::TYPE_STRING:
745-
case FieldDescriptor::TYPE_BYTES: {
746-
auto ctype = field->cpp_string_type();
747-
if (ctype == FieldDescriptor::CppStringType::kString ||
748-
ctype == FieldDescriptor::CppStringType::kView) {
749-
// strings are fine...
750-
} else if (ctype == FieldDescriptor::CppStringType::kCord) {
751-
// Cords are worth putting into the fast table, if they're not repeated
752-
if (field->is_repeated()) return false;
753-
} else {
754-
return false;
755-
}
756-
break;
757-
}
758-
759-
default:
760-
break;
761-
}
762-
763742
// The largest tag that can be read by the tailcall parser is two bytes
764743
// when varint-coded. This allows 14 bits for the numeric tag value:
765744
// byte 0 byte 1

src/google/protobuf/generated_message_tctable_impl.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ inline void AlignFail(std::integral_constant<size_t, 1>,
351351
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastU) \
352352
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBi) \
353353
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUi) \
354-
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBc) \
355-
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUc) \
354+
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastBc) \
355+
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastUc) \
356356
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastBm) \
357357
PROTOBUF_TC_PARSE_FUNCTION_LIST_SINGLE(FastUm) \
358358
PROTOBUF_TC_PARSE_FUNCTION_LIST_REPEATED(FastGd) \
@@ -648,6 +648,15 @@ class PROTOBUF_EXPORT TcParser final {
648648
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastUcS2(
649649
PROTOBUF_TC_PARAM_DECL);
650650

651+
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastBcR1(
652+
PROTOBUF_TC_PARAM_DECL);
653+
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastBcR2(
654+
PROTOBUF_TC_PARAM_DECL);
655+
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastUcR1(
656+
PROTOBUF_TC_PARAM_DECL);
657+
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastUcR2(
658+
PROTOBUF_TC_PARAM_DECL);
659+
651660
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastBmS1(
652661
PROTOBUF_TC_PARAM_DECL);
653662
PROTOBUF_NOINLINE PROTOBUF_CC static const char* FastBmS2(
@@ -1013,6 +1022,8 @@ class PROTOBUF_EXPORT TcParser final {
10131022
PROTOBUF_CC static inline const char* SingularString(PROTOBUF_TC_PARAM_DECL);
10141023
template <typename TagType, typename FieldType, Utf8Type utf8>
10151024
PROTOBUF_CC static inline const char* RepeatedString(PROTOBUF_TC_PARAM_DECL);
1025+
template <typename TagType, Utf8Type utf8>
1026+
PROTOBUF_CC static inline const char* RepeatedCord(PROTOBUF_TC_PARAM_DECL);
10161027

10171028
static inline const char* ParseRepeatedStringOnce(
10181029
const char* ptr, SerialArena* serial_arena, ParseContext* ctx,

src/google/protobuf/generated_message_tctable_lite.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,19 @@ PROTOBUF_NOINLINE const char* TcParser::FastUR2(PROTOBUF_TC_PARAM_DECL) {
18611861
PROTOBUF_TC_PARAM_PASS);
18621862
}
18631863

1864+
PROTOBUF_NOINLINE const char* TcParser::FastBcR1(PROTOBUF_TC_PARAM_DECL) {
1865+
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_NO_DATA_PASS);
1866+
}
1867+
PROTOBUF_NOINLINE const char* TcParser::FastBcR2(PROTOBUF_TC_PARAM_DECL) {
1868+
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_NO_DATA_PASS);
1869+
}
1870+
PROTOBUF_NOINLINE const char* TcParser::FastUcR1(PROTOBUF_TC_PARAM_DECL) {
1871+
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_NO_DATA_PASS);
1872+
}
1873+
PROTOBUF_NOINLINE const char* TcParser::FastUcR2(PROTOBUF_TC_PARAM_DECL) {
1874+
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_NO_DATA_PASS);
1875+
}
1876+
18641877
//////////////////////////////////////////////////////////////////////////////
18651878
// Mini parsing
18661879
//////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)