From 21453dc7381d09e6926c02c0143812680c1cfa8a Mon Sep 17 00:00:00 2001 From: tadf Date: Tue, 20 Nov 2012 12:10:08 +0000 Subject: * complex.c: some improvements. * rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'complex.c') diff --git a/complex.c b/complex.c index d4af405a88..d262e9a325 100644 --- a/complex.c +++ b/complex.c @@ -1498,13 +1498,19 @@ numeric_to_c(VALUE self) #include +inline static int +issign(int c) +{ + return (c == '-' || c == '+'); +} + static int read_sign(const char **s, char **b) { int sign = '?'; - if (**s == '-' || **s == '+') { + if (issign(**s)) { sign = **b = **s; (*s)++; (*b)++; @@ -1512,16 +1518,22 @@ read_sign(const char **s, return sign; } +inline static int +isdecimal(int c) +{ + return isdigit((unsigned char)c); +} + static int read_digits(const char **s, int strict, char **b) { int us = 1; - if (!isdigit((unsigned char)**s)) + if (!isdecimal(**s)) return 0; - while (isdigit((unsigned char)**s) || **s == '_') { + while (isdecimal(**s) || **s == '_') { if (**s == '_') { if (strict) { if (us) @@ -1543,6 +1555,12 @@ read_digits(const char **s, int strict, return 1; } +inline static int +islettere(int c) +{ + return (c == 'e' || c == 'E'); +} + static int read_num(const char **s, int strict, char **b) @@ -1562,7 +1580,7 @@ read_num(const char **s, int strict, } } - if (**s == 'e' || **s == 'E') { + if (islettere(**s)) { **b = **s; (*s)++; (*b)++; @@ -1575,7 +1593,7 @@ read_num(const char **s, int strict, return 1; } -static int +inline static int read_den(const char **s, int strict, char **b) { @@ -1612,7 +1630,7 @@ read_rat(const char **s, int strict, return 1; } -static int +inline static int isimagunit(int c) { return (c == 'i' || c == 'I' || @@ -1654,7 +1672,7 @@ read_comp(const char **s, int strict, **b = '\0'; num = str2num(bb); *ret = rb_complex_new2(num, ZERO); - return 0; /* e.g. "1/" */ + return 0; /* e.g. "-" */ } **b = '\0'; num = str2num(bb); @@ -1673,9 +1691,9 @@ read_comp(const char **s, int strict, st = read_rat(s, strict, b); **b = '\0'; if (strlen(bb) < 1 || - !isdigit((unsigned char)*(bb + strlen(bb) - 1))) { + !isdecimal(*(bb + strlen(bb) - 1))) { *ret = rb_complex_new2(num, ZERO); - return 0; /* e.g. "1@x" */ + return 0; /* e.g. "1@-" */ } num2 = str2num(bb); *ret = rb_complex_polar(num, num2); @@ -1685,7 +1703,7 @@ read_comp(const char **s, int strict, return 1; /* e.g. "1@2" */ } - if (**s == '-' || **s == '+') { + if (issign(**s)) { bb = *b; sign = read_sign(s, b); if (isimagunit(**s)) @@ -1713,7 +1731,7 @@ read_comp(const char **s, int strict, } } -static void +inline static void skip_ws(const char **s) { while (isspace((unsigned char)**s)) -- cgit v1.2.3