Refactor decode_munge to call decode_munge_int32

This avoids an additional type check when decoding packed enums.
pull/13171/head
Stan Hu 3 years ago
parent ad4d4076e1
commit ba83e135d2
No known key found for this signature in database
GPG Key ID: 8D3931AD39CC7A20
  1. 14
      upb/decode.c

@ -265,6 +265,13 @@ static const char *decode_tag(upb_decstate *d, const char *ptr, uint32_t *val) {
}
}
static void decode_munge_int32(wireval *val) {
if (!_upb_isle()) {
/* The next stage will memcpy(dst, &val, 4) */
val->uint32_val = val->uint64_val;
}
}
static void decode_munge(int type, wireval *val) {
switch (type) {
case UPB_DESCRIPTOR_TYPE_BOOL:
@ -283,10 +290,7 @@ static void decode_munge(int type, wireval *val) {
case UPB_DESCRIPTOR_TYPE_INT32:
case UPB_DESCRIPTOR_TYPE_UINT32:
case UPB_DESCRIPTOR_TYPE_ENUM:
if (!_upb_isle()) {
/* The next stage will memcpy(dst, &val, 4) */
val->uint32_val = val->uint64_val;
}
decode_munge_int32(val);
break;
}
}
@ -484,7 +488,7 @@ static const char *decode_enum_packed(upb_decstate *d, const char *ptr,
while (!decode_isdone(d, &ptr)) {
wireval elem;
ptr = decode_varint64(d, ptr, &elem.uint64_val);
decode_munge(field->descriptortype, &elem);
decode_munge_int32(&elem);
if (!decode_checkenum(d, ptr, msg, e, field, &elem)) {
continue;
}

Loading…
Cancel
Save