diff --git a/upb/decode.c b/upb/decode.c index 2eeeda7379..56aef0afda 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -305,11 +305,12 @@ static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, if (l == NULL) return &none; - size_t idx = (size_t)field_number - 1; // 0 wraps to SIZE_MAX + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX if (idx < l->dense_below) { goto found; } + /* Resume scanning from last_field_index since fields are usually in order. */ int last = *last_field_index; for (idx = last; idx < l->field_count; idx++) { if (l->fields[idx].number == field_number) { @@ -332,7 +333,7 @@ static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, } static upb_msg *decode_newsubmsg(upb_decstate *d, - const upb_msglayout *const *submsgs, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field) { const upb_msglayout *subl = submsgs[field->submsg_index]; return _upb_msg_new_inl(subl, &d->arena); @@ -365,7 +366,7 @@ static const char *decode_readstr(upb_decstate *d, const char *ptr, int size, UPB_FORCEINLINE static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, upb_msg *submsg, - const upb_msglayout *const *submsgs, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field, int size) { const upb_msglayout *subl = submsgs[field->submsg_index]; int saved_delta = decode_pushlimit(d, ptr, size); @@ -397,7 +398,7 @@ static const char *decode_group(upb_decstate *d, const char *ptr, UPB_FORCEINLINE static const char *decode_togroup(upb_decstate *d, const char *ptr, upb_msg *submsg, - const upb_msglayout *const *submsgs, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field) { const upb_msglayout *subl = submsgs[field->submsg_index]; return decode_group(d, ptr, submsg, subl, field->number); @@ -405,7 +406,7 @@ static const char *decode_togroup(upb_decstate *d, const char *ptr, static const char *decode_toarray(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *const *submsgs, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field, wireval *val, int op) { upb_array **arrp = UPB_PTR_AT(msg, field->offset, void); @@ -494,7 +495,7 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, } static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *const *submsgs, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field, wireval *val) { upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *); upb_map *map = *map_p; @@ -528,7 +529,7 @@ static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, } static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *const *submsgs, + upb_msglayout const *const *submsgs, const upb_msglayout_field *field, wireval *val, int op) { void *mem = UPB_PTR_AT(msg, field->offset, void); diff --git a/upb/def.c b/upb/def.c index 5973e7a078..97b34aa6f8 100644 --- a/upb/def.c +++ b/upb/def.c @@ -1027,7 +1027,7 @@ static void assign_layout_indices(const upb_msgdef *m, upb_msglayout *l, upb_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number); UPB_ASSERT(f); f->layout_index = i; - if (upb_fielddef_number(f) == i + 1) { + if (i <= 254 && upb_fielddef_number(f) == i + 1) { dense_below = upb_fielddef_number(f); } } diff --git a/upb/msg_internal.h b/upb/msg_internal.h index 97d711980b..9fefd53fb4 100644 --- a/upb/msg_internal.h +++ b/upb/msg_internal.h @@ -132,11 +132,7 @@ UPB_INLINE bool _upb_hasbit(const upb_msg *msg, size_t idx) { } UPB_INLINE void _upb_sethas(const upb_msg *msg, size_t idx) { - if (UPB_LIKELY(idx < 32)) { - (*UPB_PTR_AT(msg, 0, uint32_t)) |= (1UL << idx); - } else { - (*UPB_PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8)); - } + (*UPB_PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8)); } UPB_INLINE void _upb_clearhas(const upb_msg *msg, size_t idx) {