[前][次][番号順一覧][スレッド一覧]

ruby-changes:25700

From: tadf <ko1@a...>
Date: Tue, 20 Nov 2012 21:10:20 +0900 (JST)
Subject: [ruby-changes:25700] tadf:r37757 (trunk): * complex.c: some improvements.

tadf	2012-11-20 21:10:08 +0900 (Tue, 20 Nov 2012)

  New Revision: 37757

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37757

  Log:
    * complex.c: some improvements.
    * rational.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c

Index: complex.c
===================================================================
--- complex.c	(revision 37756)
+++ complex.c	(revision 37757)
@@ -1498,13 +1498,19 @@
 
 #include <ctype.h>
 
+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 @@
     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 @@
     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 @@
 	}
     }
 
-    if (**s == 'e' || **s == 'E') {
+    if (islettere(**s)) {
 	**b = **s;
 	(*s)++;
 	(*b)++;
@@ -1575,7 +1593,7 @@
     return 1;
 }
 
-static int
+inline static int
 read_den(const char **s, int strict,
 	 char **b)
 {
@@ -1612,7 +1630,7 @@
     return 1;
 }
 
-static int
+inline static int
 isimagunit(int c)
 {
     return (c == 'i' || c == 'I' ||
@@ -1654,7 +1672,7 @@
 	**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 @@
 	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 @@
 	    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 @@
     }
 }
 
-static void
+inline static void
 skip_ws(const char **s)
 {
     while (isspace((unsigned char)**s))
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37756)
+++ ChangeLog	(revision 37757)
@@ -1,3 +1,8 @@
+Tue Nov 20 21:06:41 2012  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c: some improvements.
+	* rational.c: ditto.
+
 Tue Nov 20 21:01:16 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (incs): BSD make cannot deal with non-prefixed dependency
Index: rational.c
===================================================================
--- rational.c	(revision 37756)
+++ rational.c	(revision 37757)
@@ -1958,40 +1958,53 @@
 
 #include <ctype.h>
 
+inline static int
+issign(int c)
+{
+    return (c == '-' || c == '+');
+}
+
 static int
 read_sign(const char **s)
 {
     int sign = '?';
 
-    if (**s == '-' || **s == '+') {
+    if (issign(**s)) {
 	sign = **s;
 	(*s)++;
     }
     return sign;
 }
 
+inline static int
+isdecimal(int c)
+{
+    return isdigit((unsigned char)c);
+}
+
 static int
 read_digits(const char **s, int strict,
 	    VALUE *num, int *count)
 {
-    int us = 1;
+    int us = 1, ret = 1;
+    const char *b = *s;
 
-    if (!isdigit((unsigned char)**s))
+    if (!isdecimal(**s)) {
+	*num = ZERO;
 	return 0;
+    }
 
-    *num = ZERO;
-
-    while (isdigit((unsigned char)**s) || **s == '_') {
+    while (isdecimal(**s) || **s == '_') {
 	if (**s == '_') {
 	    if (strict) {
-		if (us)
-		    return 0;
+		if (us) {
+		    ret = 0;
+		    goto conv;
+		}
 	    }
 	    us = 1;
 	}
 	else {
-	    *num = f_mul(*num, INT2FIX(10));
-	    *num = f_add(*num, INT2FIX(**s - '0'));
 	    if (count)
 		(*count)++;
 	    us = 0;
@@ -2002,9 +2015,17 @@
 	do {
 	    (*s)--;
 	} while (**s == '_');
-    return 1;
+  conv:
+    *num = rb_cstr_to_inum(b, 10, 0);
+    return ret;
 }
 
+inline static int
+islettere(int c)
+{
+    return (c == 'e' || c == 'E');
+}
+
 static int
 read_num(const char **s, int numsign, int strict,
 	 VALUE *num)
@@ -2034,7 +2055,7 @@
 	}
     }
 
-    if (**s == 'e' || **s == 'E') {
+    if (islettere(**s)) {
 	int expsign;
 
 	(*s)++;
@@ -2054,7 +2075,7 @@
     return 1;
 }
 
-static int
+inline static int
 read_den(const char **s, int strict,
 	 VALUE *num)
 {
@@ -2093,7 +2114,7 @@
     return 1;
 }
 
-static void
+inline static void
 skip_ws(const char **s)
 {
     while (isspace((unsigned char)**s))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]