From 1340195e79b8ae9cc56ebffc4241d6a5b2b12174 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 5 Oct 2022 11:50:43 -0700 Subject: [PATCH] Reduce duplication in pack by sharing code for some cases s/S, i/I, l/L, and q/Q had the same code in both cases, so combine the cases. Alternatively, we could actually the size of the unsigned type, but I doubt there are any platforms where the unsigned type is a different size than the signed type. --- pack.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pack.c b/pack.c index 7ec0290de8..9ba9bacd89 100644 --- a/pack.c +++ b/pack.c @@ -477,40 +477,24 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer) goto pack_integer; case 's': /* s for int16_t, s! for signed short */ - integer_size = NATINT_LEN(short, 2); - bigendian_p = BIGENDIAN_P(); - goto pack_integer; - case 'S': /* S for uint16_t, S! for unsigned short */ integer_size = NATINT_LEN(short, 2); bigendian_p = BIGENDIAN_P(); goto pack_integer; case 'i': /* i and i! for signed int */ - integer_size = (int)sizeof(int); - bigendian_p = BIGENDIAN_P(); - goto pack_integer; - case 'I': /* I and I! for unsigned int */ integer_size = (int)sizeof(int); bigendian_p = BIGENDIAN_P(); goto pack_integer; case 'l': /* l for int32_t, l! for signed long */ - integer_size = NATINT_LEN(long, 4); - bigendian_p = BIGENDIAN_P(); - goto pack_integer; - case 'L': /* L for uint32_t, L! for unsigned long */ integer_size = NATINT_LEN(long, 4); bigendian_p = BIGENDIAN_P(); goto pack_integer; case 'q': /* q for int64_t, q! for signed long long */ - integer_size = NATINT_LEN_Q; - bigendian_p = BIGENDIAN_P(); - goto pack_integer; - case 'Q': /* Q for uint64_t, Q! for unsigned long long */ integer_size = NATINT_LEN_Q; bigendian_p = BIGENDIAN_P();