Addressed PR comments.

pull/13171/head
Joshua Haberman 4 years ago
parent 65d7b8ab0c
commit 6394894b6e
  1. 15
      upb/decode.c
  2. 2
      upb/def.c
  3. 4
      upb/msg_internal.h

@ -305,11 +305,12 @@ static const upb_msglayout_field *upb_find_field(const upb_msglayout *l,
if (l == NULL) return &none; 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) { if (idx < l->dense_below) {
goto found; goto found;
} }
/* Resume scanning from last_field_index since fields are usually in order. */
int last = *last_field_index; int last = *last_field_index;
for (idx = last; idx < l->field_count; idx++) { for (idx = last; idx < l->field_count; idx++) {
if (l->fields[idx].number == field_number) { 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, 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_field *field) {
const upb_msglayout *subl = submsgs[field->submsg_index]; const upb_msglayout *subl = submsgs[field->submsg_index];
return _upb_msg_new_inl(subl, &d->arena); 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 UPB_FORCEINLINE
static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, static const char *decode_tosubmsg(upb_decstate *d, const char *ptr,
upb_msg *submsg, upb_msg *submsg,
const upb_msglayout *const *submsgs, upb_msglayout const *const *submsgs,
const upb_msglayout_field *field, int size) { const upb_msglayout_field *field, int size) {
const upb_msglayout *subl = submsgs[field->submsg_index]; const upb_msglayout *subl = submsgs[field->submsg_index];
int saved_delta = decode_pushlimit(d, ptr, size); 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 UPB_FORCEINLINE
static const char *decode_togroup(upb_decstate *d, const char *ptr, static const char *decode_togroup(upb_decstate *d, const char *ptr,
upb_msg *submsg, upb_msg *submsg,
const upb_msglayout *const *submsgs, upb_msglayout const *const *submsgs,
const upb_msglayout_field *field) { const upb_msglayout_field *field) {
const upb_msglayout *subl = submsgs[field->submsg_index]; const upb_msglayout *subl = submsgs[field->submsg_index];
return decode_group(d, ptr, submsg, subl, field->number); 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, static const char *decode_toarray(upb_decstate *d, const char *ptr,
upb_msg *msg, upb_msg *msg,
const upb_msglayout *const *submsgs, upb_msglayout const *const *submsgs,
const upb_msglayout_field *field, wireval *val, const upb_msglayout_field *field, wireval *val,
int op) { int op) {
upb_array **arrp = UPB_PTR_AT(msg, field->offset, void); 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, 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) { const upb_msglayout_field *field, wireval *val) {
upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *); upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *);
upb_map *map = *map_p; 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, 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, const upb_msglayout_field *field, wireval *val,
int op) { int op) {
void *mem = UPB_PTR_AT(msg, field->offset, void); void *mem = UPB_PTR_AT(msg, field->offset, void);

@ -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_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number);
UPB_ASSERT(f); UPB_ASSERT(f);
f->layout_index = i; 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); dense_below = upb_fielddef_number(f);
} }
} }

@ -132,12 +132,8 @@ UPB_INLINE bool _upb_hasbit(const upb_msg *msg, size_t idx) {
} }
UPB_INLINE void _upb_sethas(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) { UPB_INLINE void _upb_clearhas(const upb_msg *msg, size_t idx) {
(*UPB_PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8))); (*UPB_PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8)));

Loading…
Cancel
Save