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

ruby-changes:42855

From: nobu <ko1@a...>
Date: Fri, 6 May 2016 14:56:00 +0900 (JST)
Subject: [ruby-changes:42855] nobu:r54929 (trunk): random.c: prefer rb_check_arity

nobu	2016-05-06 15:52:36 +0900 (Fri, 06 May 2016)

  New Revision: 54929

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

  Log:
    random.c: prefer rb_check_arity
    
    * random.c: use rb_check_arity instead of rb_scan_args for simple
      optional arguments.

  Modified files:
    trunk/random.c
Index: random.c
===================================================================
--- random.c	(revision 54928)
+++ random.c	(revision 54929)
@@ -426,12 +426,12 @@ random_init(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/random.c#L426
     VALUE vseed;
     rb_random_t *rnd = get_rnd(obj);
 
-    if (argc == 0) {
+    if (rb_check_arity(argc, 0, 1) == 0) {
 	rb_check_frozen(obj);
 	vseed = random_seed();
     }
     else {
-	rb_scan_args(argc, argv, "01", &vseed);
+	vseed = argv[0];
 	rb_check_copyable(obj, vseed);
     }
     rnd->seed = rand_init(&rnd->mt, vseed);
@@ -793,11 +793,11 @@ rb_f_srand(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/random.c#L793
     VALUE seed, old;
     rb_random_t *r = &default_rand;
 
-    if (argc == 0) {
+    if (rb_check_arity(argc, 0, 1) == 0) {
 	seed = random_seed();
     }
     else {
-	rb_scan_args(argc, argv, "01", &seed);
+	seed = argv[0];
     }
     old = r->seed;
     r->seed = rand_init(&r->mt, seed);
@@ -1407,8 +1407,8 @@ rb_f_rand(int argc, VALUE *argv, VALUE o https://github.com/ruby/ruby/blob/trunk/random.c#L1407
     VALUE v, vmax, r;
     rb_random_t *rnd = rand_start(&default_rand);
 
-    if (argc == 0) goto zero_arg;
-    rb_scan_args(argc, argv, "01", &vmax);
+    if (rb_check_arity(argc, 0, 1) == 0) goto zero_arg;
+    vmax = argv[0];
     if (NIL_P(vmax)) goto zero_arg;
     if ((v = rand_range(Qnil, rnd, vmax)) != Qfalse) {
 	return v;

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

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