aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-03 13:32:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-03 13:32:14 +0000
commitb2be623240af7b3318596fa348d2c7920f8703b5 (patch)
tree475d7bd4aeac575fe74120e102be3a2211c4f313
parent48ebea719f4478245a90352cfbfd5146ce65ca9e (diff)
downloadruby-b2be623240af7b3318596fa348d2c7920f8703b5.tar.gz
* 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
-rw-r--r--ChangeLog10
-rw-r--r--bignum.c7
-rw-r--r--internal.h3
-rw-r--r--pack.c18
-rw-r--r--util.c41
5 files changed, 40 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index a7a0d15f99..23ba86bdd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Jul 3 22:29:20 2013 Tanaka Akira <akr@fsij.org>
+
+ * 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.
+
Wed Jul 3 18:12:56 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (install_dirs): revert DESTDIR prefix by r39841, since
diff --git a/bignum.c b/bignum.c
index 3d66c8a1ad..27be47f64b 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1916,12 +1916,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
#undef ISDIGIT
#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
-#define conv_digit(c) \
- (!ISASCII(c) ? -1 : \
- ISDIGIT(c) ? ((c) - '0') : \
- ISLOWER(c) ? ((c) - 'a' + 10) : \
- ISUPPER(c) ? ((c) - 'A' + 10) : \
- -1)
+#define conv_digit(c) (ruby_digit36_to_number_table[(unsigned char)(c)])
if (!str) {
if (badcheck) goto bad;
diff --git a/internal.h b/internal.h
index 84ef95fe11..edccd4cc99 100644
--- a/internal.h
+++ b/internal.h
@@ -530,6 +530,9 @@ int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, cha
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
+/* util.c */
+extern const signed char ruby_digit36_to_number_table[];
+
/* variable.c */
void rb_gc_mark_global_tbl(void);
void rb_mark_generic_ivar(VALUE);
diff --git a/pack.c b/pack.c
index 67b0bc2368..aba976aad7 100644
--- a/pack.c
+++ b/pack.c
@@ -1047,19 +1047,11 @@ qpencode(VALUE str, VALUE from, long len)
static inline int
hex2num(char c)
{
- switch (c) {
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- return c - '0';
- case 'a': case 'b': case 'c':
- case 'd': case 'e': case 'f':
- return c - 'a' + 10;
- case 'A': case 'B': case 'C':
- case 'D': case 'E': case 'F':
- return c - 'A' + 10;
- default:
- return -1;
- }
+ int n;
+ n = ruby_digit36_to_number_table[(unsigned char)c];
+ if (16 <= n)
+ n = -1;
+ return n;
}
#define PACK_LENGTH_ADJUST_SIZE(sz) do { \
diff --git a/util.c b/util.c
index 93d0547498..827cca45d4 100644
--- a/util.c
+++ b/util.c
@@ -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;