From ba83e135d2f3a8f909a09905b449d4555aca063e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 2 Nov 2021 13:53:31 -0700 Subject: [PATCH] Refactor decode_munge to call decode_munge_int32 This avoids an additional type check when decoding packed enums. --- upb/decode.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/upb/decode.c b/upb/decode.c index a91a7770e7..822694fcb2 100644 --- a/upb/decode.c +++ b/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; }