Look up ruby_digit36_to_number_table

Instead of scanning ruby_hexdigits.
This commit is contained in:
Nobuyoshi Nakada 2021-07-20 19:54:59 +09:00
parent b2749e0026
commit 04b5e85bfd
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
1 changed files with 4 additions and 7 deletions

11
util.c
View File

@ -57,19 +57,16 @@ ruby_scan_hex(const char *start, size_t len, size_t *retlen)
{
register const char *s = start;
register unsigned long retval = 0;
const char *tmp;
signed char d;
size_t i = 0;
for (i = 0; i < len; i++) {
if (! s[0]) {
break;
}
tmp = strchr(hexdigit, *s);
if (! tmp) {
d = ruby_digit36_to_number_table[(unsigned char)*s];
if (d < 0 || 15 < d) {
break;
}
retval <<= 4;
retval |= (tmp - hexdigit) & 15;
retval |= d;
s++;
}
*retlen = (int)(s - start); /* less than len */