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

ruby-changes:33778

From: nobu <ko1@a...>
Date: Wed, 7 May 2014 17:05:09 +0900 (JST)
Subject: [ruby-changes:33778] nobu:r45859 (trunk): numeric.c: num_step_scan_args

nobu	2014-05-07 17:05:00 +0900 (Wed, 07 May 2014)

  New Revision: 45859

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

  Log:
    numeric.c: num_step_scan_args
    
    * numeric.c (num_step_scan_args): turn a macro into a function.

  Modified files:
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 45858)
+++ numeric.c	(revision 45859)
@@ -1859,39 +1859,44 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/numeric.c#L1859
     }
 }
 
-#define NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc) do {	\
-    argc = rb_scan_args(argc, argv, "02:", &to, &step, &hash);		\
-    if (!NIL_P(hash)) {							\
-	step = rb_hash_aref(hash, sym_by);				\
-	to = rb_hash_aref(hash, sym_to);				\
-    }									\
-    else {								\
-	/* compatibility */						\
-        if (argc > 1 && NIL_P(step)) {				       	\
-            rb_raise(rb_eTypeError, "step must be numeric");		\
-	}								\
-	if (rb_equal(step, INT2FIX(0))) {				\
-	    rb_raise(rb_eArgError, "step can't be 0");			\
-	}								\
-    }									\
-    if (NIL_P(step)) {							\
-        step = INT2FIX(1);						\
-    }									\
-    desc = !positive_int_p(step);					\
-    if (NIL_P(to)) {							\
-        to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);		\
-    }									\
-} while (0)
+static int
+num_step_scan_args(int argc, const VALUE *argv, VALUE *to, VALUE *step)
+{
+    VALUE hash;
+    int desc;
+
+    argc = rb_scan_args(argc, argv, "02:", to, step, &hash);
+    if (!NIL_P(hash)) {
+	step = rb_hash_aref(hash, sym_by);
+	to = rb_hash_aref(hash, sym_to);
+    }
+    else {
+	/* compatibility */
+	if (argc > 1 && NIL_P(*step)) {
+	    rb_raise(rb_eTypeError, "step must be numeric");
+	}
+	if (rb_equal(*step, INT2FIX(0))) {
+	    rb_raise(rb_eArgError, "step can't be 0");
+	}
+    }
+    if (NIL_P(*step)) {
+	*step = INT2FIX(1);
+    }
+    desc = !positive_int_p(*step);
+    if (NIL_P(*to)) {
+	*to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
+    }
+    return desc;
+}
 
 static VALUE
 num_step_size(VALUE from, VALUE args, VALUE eobj)
 {
-    VALUE to, step, hash;
-    int desc;
+    VALUE to, step;
     int argc = args ? RARRAY_LENINT(args) : 0;
     const VALUE *argv = args ? RARRAY_CONST_PTR(args) : 0;
 
-    NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc);
+    num_step_scan_args(argc, argv, &to, &step);
 
     return ruby_num_interval_step_size(from, to, step, FALSE);
 }
@@ -1952,12 +1957,12 @@ num_step_size(VALUE from, VALUE args, VA https://github.com/ruby/ruby/blob/trunk/numeric.c#L1957
 static VALUE
 num_step(int argc, VALUE *argv, VALUE from)
 {
-    VALUE to, step, hash;
+    VALUE to, step;
     int desc, inf;
 
     RETURN_SIZED_ENUMERATOR(from, argc, argv, num_step_size);
 
-    NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc);
+    desc = num_step_scan_args(argc, argv, &to, &step);
     if (RTEST(rb_num_coerce_cmp(step, INT2FIX(0), id_eq))) {
 	inf = 1;
     }

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

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