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

ruby-changes:30715

From: akr <ko1@a...>
Date: Tue, 3 Sep 2013 12:03:40 +0900 (JST)
Subject: [ruby-changes:30715] akr:r42794 (trunk): * bignum.c (str2big_scan_digits): Extracted from rb_cstr_to_inum.

akr	2013-09-03 12:03:32 +0900 (Tue, 03 Sep 2013)

  New Revision: 42794

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

  Log:
    * bignum.c (str2big_scan_digits): Extracted from rb_cstr_to_inum.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42793)
+++ ChangeLog	(revision 42794)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Sep  3 12:03:02 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (str2big_scan_digits): Extracted from rb_cstr_to_inum.
+
 Tue Sep  3 11:23:57 2013  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (rb_w32_select_with_thread): rounding up the fraction of
Index: bignum.c
===================================================================
--- bignum.c	(revision 42793)
+++ bignum.c	(revision 42794)
@@ -3571,6 +3571,48 @@ rb_quad_unpack(const char *buf, int sign https://github.com/ruby/ruby/blob/trunk/bignum.c#L3571
 
 #define conv_digit(c) (ruby_digit36_to_number_table[(unsigned char)(c)])
 
+static void
+str2big_scan_digits(const char *s, const char *str, int base, int badcheck, size_t *num_digits_p, size_t *len_p)
+{
+    char nondigit = 0;
+    size_t num_digits = 0;
+    const char *digits_start = str;
+    const char *digits_end = str;
+
+    int c;
+
+    if (badcheck && *str == '_') goto bad;
+
+    while ((c = *str++) != 0) {
+	if (c == '_') {
+	    if (nondigit) {
+		if (badcheck) goto bad;
+		break;
+	    }
+	    nondigit = (char) c;
+	    continue;
+	}
+	else if ((c = conv_digit(c)) < 0) {
+	    break;
+	}
+	if (c >= base) break;
+	nondigit = 0;
+        num_digits++;
+        digits_end = str;
+    }
+    if (badcheck) {
+	str--;
+	if (s+1 < str && str[-1] == '_') goto bad;
+	while (*str && ISSPACE(*str)) str++;
+	if (*str) {
+	  bad:
+	    rb_invalid_str(s, "Integer()");
+	}
+    }
+    *num_digits_p = num_digits;
+    *len_p = digits_end - digits_start;
+}
+
 static VALUE
 str2big_poweroftwo(
     int sign,
@@ -3743,7 +3785,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/bignum.c#L3785
 rb_cstr_to_inum(const char *str, int base, int badcheck)
 {
     const char *s = str;
-    char sign = 1, nondigit = 0;
+    char sign = 1;
     int c;
     VALUE z;
 
@@ -3752,9 +3794,13 @@ rb_cstr_to_inum(const char *str, int bas https://github.com/ruby/ruby/blob/trunk/bignum.c#L3794
     const char *digits_start, *digits_end;
     size_t num_digits;
     size_t num_bdigits;
+    size_t len;
 
     if (!str) {
-	if (badcheck) goto bad;
+	if (badcheck) {
+          bad:
+            rb_invalid_str(s, "Integer()");
+        }
 	return INT2FIX(0);
     }
     while (ISSPACE(*str)) str++;
@@ -3868,36 +3914,9 @@ rb_cstr_to_inum(const char *str, int bas https://github.com/ruby/ruby/blob/trunk/bignum.c#L3914
     }
 
   bigparse:
-    if (badcheck && *str == '_') goto bad;
-
-    num_digits = 0;
-    digits_start = digits_end = str;
-    while ((c = *str++) != 0) {
-	if (c == '_') {
-	    if (nondigit) {
-		if (badcheck) goto bad;
-		break;
-	    }
-	    nondigit = (char) c;
-	    continue;
-	}
-	else if ((c = conv_digit(c)) < 0) {
-	    break;
-	}
-	if (c >= base) break;
-	nondigit = 0;
-        num_digits++;
-        digits_end = str;
-    }
-    if (badcheck) {
-	str--;
-	if (s+1 < str && str[-1] == '_') goto bad;
-	while (*str && ISSPACE(*str)) str++;
-	if (*str) {
-	  bad:
-	    rb_invalid_str(s, "Integer()");
-	}
-    }
+    digits_start = str;
+    str2big_scan_digits(s, str, base, badcheck, &num_digits, &len);
+    digits_end = digits_start + len;
 
     if (POW2_P(base)) {
         z = str2big_poweroftwo(sign, digits_start, digits_end, num_digits,

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

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