mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Extract code fragment for unpacking into method in sym_inline_unpack()
This commit is contained in:
+14
-19
@@ -69,31 +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++) {
|
||||
uint32_t bits;
|
||||
char c;
|
||||
|
||||
bits = sym>>(i*5+2) & 31;
|
||||
if (bits == 0) break;
|
||||
c = pack_table[bits-1];
|
||||
buf[i] = c;
|
||||
}
|
||||
buf[i] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
for (i=0; i<5; i++) {
|
||||
for (i=0; i<30/bit_per_char; i++) {
|
||||
uint32_t bits;
|
||||
char c;
|
||||
|
||||
bits = sym>>(i*6+2) & 63;
|
||||
bits = sym>>(i*bit_per_char+2) & (1<<bit_per_char)-1;
|
||||
if (bits == 0) break;
|
||||
c = pack_table[bits-1];
|
||||
buf[i] = c;
|
||||
@@ -101,6 +85,17 @@ sym_inline_unpack(mrb_sym sym, char *buf)
|
||||
buf[i] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
static const char*
|
||||
sym_inline_unpack(mrb_sym sym, char *buf)
|
||||
{
|
||||
mrb_assert(sym&1);
|
||||
|
||||
if (sym&2) { /* all lower case (5bits/char) */
|
||||
return sym_inline_unpack_with_bit(sym, buf, 5);
|
||||
}
|
||||
return sym_inline_unpack_with_bit(sym, buf, 6);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t
|
||||
|
||||
Reference in New Issue
Block a user