diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-03 13:32:14 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-03 13:32:14 +0000 |
commit | b2be623240af7b3318596fa348d2c7920f8703b5 (patch) | |
tree | 475d7bd4aeac575fe74120e102be3a2211c4f313 /util.c | |
parent | 48ebea719f4478245a90352cfbfd5146ce65ca9e (diff) |
* internal.h (ruby_digit36_to_number_table): Declared.
* util.c (ruby_digit36_to_number_table): Moved from scan_digits.
* bignum.c (conv_digit): Use ruby_digit36_to_number_table.
* pack.c (hex2num): Ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -55,28 +55,29 @@ ruby_scan_hex(const char *start, size_t len, size_t *retlen) return retval; } +const signed char ruby_digit36_to_number_table[] = { + /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ + /*0*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*1*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*2*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*3*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, + /*4*/ -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, + /*5*/ 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, + /*6*/ -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, + /*7*/ 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, + /*8*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*9*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*a*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*b*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*c*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*d*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*e*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /*f*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +}; + static unsigned long scan_digits(const char *str, int base, size_t *retlen, int *overflow) { - static const signed char table[] = { - /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ - /*0*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*1*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*2*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*3*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, - /*4*/ -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, - /*5*/ 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, - /*6*/ -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, - /*7*/ 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, - /*8*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*9*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*a*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*b*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*c*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*d*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*e*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - /*f*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - }; const char *start = str; unsigned long ret = 0, x; @@ -85,7 +86,7 @@ scan_digits(const char *str, int base, size_t *retlen, int *overflow) *overflow = 0; while ((c = (unsigned char)*str++) != '\0') { - int d = table[c]; + int d = ruby_digit36_to_number_table[c]; if (d == -1 || base <= d) { *retlen = (str-1) - start; return ret; |