Extract code fragment for unpacking into method in `sym_inline_unpack()`
MODIFY
src/symbol.c
src/symbol.c
@@ -69,18 +69,15 @@ sym_inline_pack(const char *name, uint16_t len)
}
static const char*
-sym_inline_unpack(mrb_sym sym, char *buf)
+sym_inline_unpack_with_bit(mrb_sym sym, char *buf, int bit_per_char)
{
int i;
- mrb_assert(sym&1);
-
- if (sym&2) { /* all lower case (5bits/char) */
- for (i=0; i<6; i++) {
+ for (i=0; i<30/bit_per_char; i++) {
uint32_t bits;
char c;
- bits = sym>>(i*5+2) & 31;
+ bits = sym>>(i*bit_per_char+2) & (1<<bit_per_char)-1;
if (bits == 0) break;
c = pack_table[bits-1];
buf[i] = c;
@@ -89,17 +86,15 @@ sym_inline_unpack(mrb_sym sym, char *buf)
return buf;
}
- for (i=0; i<5; i++) {
- uint32_t bits;
- char c;
+static const char*
+sym_inline_unpack(mrb_sym sym, char *buf)
+{
+ mrb_assert(sym&1);
- bits = sym>>(i*6+2) & 63;
- if (bits == 0) break;
- c = pack_table[bits-1];
- buf[i] = c;
+ if (sym&2) { /* all lower case (5bits/char) */
+ return sym_inline_unpack_with_bit(sym, buf, 5);
}
- buf[i] = '\0';
- return buf;
+ return sym_inline_unpack_with_bit(sym, buf, 6);
}
#endif

Extract code fragment for unpacking into method in `sym_inline_unpack()`