diff options
author | Andy Wingo <wingo@pobox.com> | 2013-08-31 11:15:01 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-08-31 11:15:01 +0200 |
commit | 6871327742d3e1a0966aa8fed04c911311c12c2a (patch) | |
tree | 9263df04f46a934e6f8b5deda009f4f825723f77 | |
parent | 25752c4d1cef1049578d6b9b2cd0b6e44b8b8de7 (diff) | |
download | guile-6871327742d3e1a0966aa8fed04c911311c12c2a.tar.gz |
Micro-optimize char_decimal_value.
* libguile/numbers.c (char_decimal_value): A wee micro-optimization.
-rw-r--r-- | libguile/numbers.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/libguile/numbers.c b/libguile/numbers.c index b5bce2308..7ccbeecf3 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -5798,20 +5798,25 @@ enum t_exactness {NO_EXACTNESS, INEXACT, EXACT}; static unsigned int char_decimal_value (scm_t_uint32 c) { - /* uc_decimal_value returns -1 on error. When cast to an unsigned int, - that's certainly above any valid decimal, so we take advantage of - that to elide some tests. */ - unsigned int d = (unsigned int) uc_decimal_value (c); - - /* If that failed, try extended hexadecimals, then. Only accept ascii - hexadecimals. */ - if (d >= 10U) + if (c >= (scm_t_uint32) '0' && c <= (scm_t_uint32) '9') + return c - (scm_t_uint32) '0'; + else { - c = uc_tolower (c); - if (c >= (scm_t_uint32) 'a') - d = c - (scm_t_uint32)'a' + 10U; + /* uc_decimal_value returns -1 on error. When cast to an unsigned int, + that's certainly above any valid decimal, so we take advantage of + that to elide some tests. */ + unsigned int d = (unsigned int) uc_decimal_value (c); + + /* If that failed, try extended hexadecimals, then. Only accept ascii + hexadecimals. */ + if (d >= 10U) + { + c = uc_tolower (c); + if (c >= (scm_t_uint32) 'a') + d = c - (scm_t_uint32)'a' + 10U; + } + return d; } - return d; } /* Parse the substring of MEM starting at *P_IDX for an unsigned integer |