@@ -7591,20 +7591,6 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
7591
7591
return ptr;
7592
7592
}
7593
7593
7594
- UPB_FORCEINLINE
7595
- bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr,
7596
- upb_Message* msg, const upb_MiniTable* m) {
7597
- #if UPB_FASTTABLE
7598
- if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) {
7599
- uint16_t tag = _upb_FastDecoder_LoadTag(*ptr);
7600
- intptr_t table = decode_totable(m);
7601
- *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag);
7602
- return true;
7603
- }
7604
- #endif
7605
- return false;
7606
- }
7607
-
7608
7594
static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr,
7609
7595
uint32_t tag) {
7610
7596
int field_number = tag >> 3;
@@ -8087,79 +8073,115 @@ static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
8087
8073
return ptr;
8088
8074
}
8089
8075
8090
- UPB_NOINLINE
8091
- const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
8092
- upb_Message* msg,
8093
- const upb_MiniTable* layout) {
8094
- #if UPB_FASTTABLE
8095
- // The first time we want to skip fast dispatch, because we may have just been
8096
- // invoked by the fast parser to handle a case that it bailed on.
8097
- if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast;
8076
+ UPB_FORCEINLINE
8077
+ const char* _upb_Decoder_DecodeFieldTag(upb_Decoder* d, const char* ptr,
8078
+ int* field_number, int* wire_type) {
8079
+ #ifndef NDEBUG
8080
+ d->debug_tagstart = ptr;
8098
8081
#endif
8099
8082
8100
- while (!_upb_Decoder_IsDone(d, &ptr)) {
8101
- uint32_t tag;
8102
- const upb_MiniTableField* field;
8103
- int field_number;
8104
- int wire_type;
8105
- wireval val;
8106
- int op;
8107
-
8108
- if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break;
8109
-
8110
- #if UPB_FASTTABLE
8111
- nofast:
8112
- #endif
8083
+ uint32_t tag;
8084
+ UPB_ASSERT(ptr < d->input.limit_ptr);
8085
+ ptr = _upb_Decoder_DecodeTag(d, ptr, &tag);
8086
+ *field_number = tag >> 3;
8087
+ *wire_type = tag & 7;
8088
+ return ptr;
8089
+ }
8113
8090
8091
+ UPB_FORCEINLINE
8092
+ const char* _upb_Decoder_DecodeFieldData(upb_Decoder* d, const char* ptr,
8093
+ upb_Message* msg,
8094
+ const upb_MiniTable* mt,
8095
+ int field_number, int wire_type) {
8114
8096
#ifndef NDEBUG
8115
- d->debug_tagstart = ptr;
8097
+ d->debug_valstart = ptr;
8116
8098
#endif
8117
8099
8118
- UPB_ASSERT(ptr < d->input.limit_ptr);
8119
- ptr = _upb_Decoder_DecodeTag(d, ptr, &tag);
8120
- field_number = tag >> 3;
8121
- wire_type = tag & 7;
8100
+ int op;
8101
+ wireval val;
8122
8102
8123
- #ifndef NDEBUG
8124
- d->debug_valstart = ptr ;
8125
- #endif
8103
+ const upb_MiniTableField* field =
8104
+ _upb_Decoder_FindField(d, mt, field_number, wire_type) ;
8105
+ ptr = _upb_Decoder_DecodeWireValue(d, ptr, mt, field, wire_type, &val, &op);
8126
8106
8127
- if (wire_type == kUpb_WireType_EndGroup) {
8128
- d->end_group = field_number;
8129
- return ptr;
8107
+ if (op >= 0) {
8108
+ return _upb_Decoder_DecodeKnownField(d, ptr, msg, mt, field, op, &val);
8109
+ } else {
8110
+ switch (op) {
8111
+ case kUpb_DecodeOp_UnknownField:
8112
+ return _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number,
8113
+ wire_type, val);
8114
+ case kUpb_DecodeOp_MessageSetItem:
8115
+ return upb_Decoder_DecodeMessageSetItem(d, ptr, msg, mt);
8116
+ default:
8117
+ UPB_UNREACHABLE();
8130
8118
}
8119
+ }
8120
+ }
8131
8121
8132
- field = _upb_Decoder_FindField(d, layout, field_number, wire_type);
8133
- ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val,
8134
- &op);
8122
+ static const char* _upb_Decoder_EndMessage(upb_Decoder* d, const char* ptr) {
8123
+ d->message_is_done = true;
8124
+ return ptr;
8125
+ }
8135
8126
8136
- if (op >= 0) {
8137
- ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val);
8138
- } else {
8139
- switch (op) {
8140
- case kUpb_DecodeOp_UnknownField:
8141
- ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number,
8142
- wire_type, val);
8143
- break;
8144
- case kUpb_DecodeOp_MessageSetItem:
8145
- ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout);
8146
- break;
8147
- }
8148
- }
8127
+ UPB_FORCEINLINE
8128
+ const char* _upb_Decoder_DecodeFieldNoFast(upb_Decoder* d, const char* ptr,
8129
+ upb_Message* msg,
8130
+ const upb_MiniTable* mt) {
8131
+ int field_number;
8132
+ int wire_type;
8133
+
8134
+ ptr = _upb_Decoder_DecodeFieldTag(d, ptr, &field_number, &wire_type);
8135
+
8136
+ if (wire_type == kUpb_WireType_EndGroup) {
8137
+ d->end_group = field_number;
8138
+ return _upb_Decoder_EndMessage(d, ptr);
8139
+ }
8140
+
8141
+ return _upb_Decoder_DecodeFieldData(d, ptr, msg, mt, field_number, wire_type);
8142
+ }
8143
+
8144
+ UPB_FORCEINLINE
8145
+ const char* _upb_Decoder_DecodeField(upb_Decoder* d, const char* ptr,
8146
+ upb_Message* msg, const upb_MiniTable* mt,
8147
+ uint64_t last_field_index, uint64_t data) {
8148
+ if (_upb_Decoder_IsDone(d, &ptr)) {
8149
+ return _upb_Decoder_EndMessage(d, ptr);
8150
+ }
8151
+
8152
+ #if UPB_FASTTABLE
8153
+ if (mt && mt->UPB_PRIVATE(table_mask) != (unsigned char)-1) {
8154
+ uint16_t tag = _upb_FastDecoder_LoadTag(ptr);
8155
+ intptr_t table = decode_totable(mt);
8156
+ ptr = _upb_FastDecoder_TagDispatch(d, ptr, msg, table, 0, tag);
8157
+ if (d->message_is_done) return ptr;
8149
8158
}
8159
+ #endif
8160
+
8161
+ return _upb_Decoder_DecodeFieldNoFast(d, ptr, msg, mt);
8162
+ }
8163
+
8164
+ UPB_NOINLINE
8165
+ const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
8166
+ upb_Message* msg,
8167
+ const upb_MiniTable* mt) {
8168
+ UPB_ASSERT(d->message_is_done == false);
8169
+
8170
+ do {
8171
+ ptr = _upb_Decoder_DecodeField(d, ptr, msg, mt, 0, 0);
8172
+ } while (!d->message_is_done);
8173
+ d->message_is_done = false;
8150
8174
8151
- return UPB_UNLIKELY(layout && layout ->UPB_PRIVATE(required_count))
8152
- ? _upb_Decoder_CheckRequired(d, ptr, msg, layout )
8175
+ return UPB_UNLIKELY(mt && mt ->UPB_PRIVATE(required_count))
8176
+ ? _upb_Decoder_CheckRequired(d, ptr, msg, mt )
8153
8177
: ptr;
8154
8178
}
8155
8179
8156
8180
static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d,
8157
8181
const char* buf,
8158
8182
upb_Message* msg,
8159
8183
const upb_MiniTable* m) {
8160
- if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, m)) {
8161
- _upb_Decoder_DecodeMessage(d, buf, msg, m);
8162
- }
8184
+ _upb_Decoder_DecodeMessage(d, buf, msg, m);
8163
8185
if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed;
8164
8186
if (d->missing_required) return kUpb_DecodeStatus_MissingRequired;
8165
8187
return kUpb_DecodeStatus_Ok;
@@ -8209,6 +8231,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
8209
8231
decoder.options = (uint16_t)options;
8210
8232
decoder.missing_required = false;
8211
8233
decoder.status = kUpb_DecodeStatus_Ok;
8234
+ decoder.message_is_done = false;
8212
8235
8213
8236
// Violating the encapsulation of the arena for performance reasons.
8214
8237
// This is a temporary arena that we swap into and swap out of when we are
0 commit comments