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

ruby-changes:53959

From: nobu <ko1@a...>
Date: Tue, 4 Dec 2018 11:24:20 +0900 (JST)
Subject: [ruby-changes:53959] nobu:r66179 (trunk): Prefer rb_check_arity when 0 or 1 arguments

nobu	2018-12-04 11:24:15 +0900 (Tue, 04 Dec 2018)

  New Revision: 66179

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66179

  Log:
    Prefer rb_check_arity when 0 or 1 arguments

  Modified files:
    trunk/array.c
    trunk/complex.c
    trunk/rational.c
    trunk/re.c
    trunk/time.c
Index: complex.c
===================================================================
--- complex.c	(revision 66178)
+++ complex.c	(revision 66179)
@@ -1491,7 +1491,7 @@ nucomp_rationalize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/complex.c#L1491
 {
     get_dat1(self);
 
-    rb_scan_args(argc, argv, "01", NULL);
+    rb_check_arity(argc, 0, 1);
 
     if (!k_exact_zero_p(dat->imag)) {
        rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
Index: rational.c
===================================================================
--- rational.c	(revision 66178)
+++ rational.c	(revision 66179)
@@ -2121,7 +2121,7 @@ nilclass_to_r(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L2121
 static VALUE
 nilclass_rationalize(int argc, VALUE *argv, VALUE self)
 {
-    rb_scan_args(argc, argv, "01", NULL);
+    rb_check_arity(argc, 0, 1);
     return nilclass_to_r(self);
 }
 
@@ -2150,7 +2150,7 @@ integer_to_r(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L2150
 static VALUE
 integer_rationalize(int argc, VALUE *argv, VALUE self)
 {
-    rb_scan_args(argc, argv, "01", NULL);
+    rb_check_arity(argc, 0, 1);
     return integer_to_r(self);
 }
 
Index: time.c
===================================================================
--- time.c	(revision 66178)
+++ time.c	(revision 66179)
@@ -4959,7 +4959,7 @@ time_dump(int argc, VALUE *argv, VALUE t https://github.com/ruby/ruby/blob/trunk/time.c#L4959
 {
     VALUE str;
 
-    rb_scan_args(argc, argv, "01", 0);
+    rb_check_arity(argc, 0, 1);
     str = time_mdump(time);
 
     return str;
Index: array.c
===================================================================
--- array.c	(revision 66178)
+++ array.c	(revision 66179)
@@ -2590,13 +2590,7 @@ rb_ary_rotate(VALUE ary, long cnt) https://github.com/ruby/ruby/blob/trunk/array.c#L2590
 static VALUE
 rb_ary_rotate_bang(int argc, VALUE *argv, VALUE ary)
 {
-    long n = 1;
-
-    switch (argc) {
-      case 1: n = NUM2LONG(argv[0]);
-      case 0: break;
-      default: rb_scan_args(argc, argv, "01", NULL);
-    }
+    long n = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
     rb_ary_rotate(ary, n);
     return ary;
 }
@@ -2623,13 +2617,8 @@ rb_ary_rotate_m(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/array.c#L2617
 {
     VALUE rotated;
     const VALUE *ptr;
-    long len, cnt = 1;
-
-    switch (argc) {
-      case 1: cnt = NUM2LONG(argv[0]);
-      case 0: break;
-      default: rb_scan_args(argc, argv, "01", NULL);
-    }
+    long len;
+    long cnt = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
 
     len = RARRAY_LEN(ary);
     rotated = rb_ary_new2(len);
Index: re.c
===================================================================
--- re.c	(revision 66178)
+++ re.c	(revision 66179)
@@ -3960,13 +3960,11 @@ match_setter(VALUE val) https://github.com/ruby/ruby/blob/trunk/re.c#L3960
 static VALUE
 rb_reg_s_last_match(int argc, VALUE *argv)
 {
-    VALUE nth;
-
-    if (argc > 0 && rb_scan_args(argc, argv, "01", &nth) == 1) {
+    if (rb_check_arity(argc, 0, 1) == 1) {
         VALUE match = rb_backref_get();
         int n;
         if (NIL_P(match)) return Qnil;
-        n = match_backref_number(match, nth);
+        n = match_backref_number(match, argv[0]);
 	return rb_reg_nth_match(n, match);
     }
     return match_getter();

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

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