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

ruby-changes:34579

From: nobu <ko1@a...>
Date: Wed, 2 Jul 2014 17:25:39 +0900 (JST)
Subject: [ruby-changes:34579] nobu:r46660 (trunk): hash.c: use rb_check_arity

nobu	2014-07-02 17:25:21 +0900 (Wed, 02 Jul 2014)

  New Revision: 46660

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

  Log:
    hash.c: use rb_check_arity
    
    * hash.c (rb_hash_initialize, rb_hash_fetch_m, rb_hash_default):
      use rb_check_arity over rb_scan_args.
      (env_fetch): ditto.

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 46659)
+++ hash.c	(revision 46660)
@@ -499,7 +499,8 @@ rb_hash_initialize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/hash.c#L499
 	FL_SET(hash, HASH_PROC_DEFAULT);
     }
     else {
-	rb_scan_args(argc, argv, "01", &ifnone);
+	rb_check_arity(argc, 0, 1);
+	ifnone = argc == 0 ? Qnil : argv[0];
 	RHASH_SET_IFNONE(hash, ifnone);
     }
 
@@ -766,11 +767,12 @@ rb_hash_lookup(VALUE hash, VALUE key) https://github.com/ruby/ruby/blob/trunk/hash.c#L767
 static VALUE
 rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
 {
-    VALUE key, if_none;
+    VALUE key;
     st_data_t val;
     long block_given;
 
-    rb_scan_args(argc, argv, "11", &key, &if_none);
+    rb_check_arity(argc, 1, 2);
+    key = argv[0];
 
     block_given = rb_block_given_p();
     if (block_given && argc == 2) {
@@ -786,7 +788,7 @@ rb_hash_fetch_m(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/hash.c#L788
 	    desc = rb_str_ellipsize(desc, 65);
 	    rb_raise(rb_eKeyError, "key not found: %"PRIsVALUE, desc);
 	}
-	return if_none;
+	return argv[1];
     }
     return (VALUE)val;
 }
@@ -823,7 +825,8 @@ rb_hash_default(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/hash.c#L825
 {
     VALUE key, ifnone;
 
-    rb_scan_args(argc, argv, "01", &key);
+    rb_check_arity(argc, 0, 1);
+    key = argv[0];
     ifnone = RHASH_IFNONE(hash);
     if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
 	if (argc == 0) return Qnil;
@@ -2637,11 +2640,12 @@ rb_f_getenv(VALUE obj, VALUE name) https://github.com/ruby/ruby/blob/trunk/hash.c#L2640
 static VALUE
 env_fetch(int argc, VALUE *argv)
 {
-    VALUE key, if_none;
+    VALUE key;
     long block_given;
     const char *nam, *env;
 
-    rb_scan_args(argc, argv, "11", &key, &if_none);
+    rb_check_arity(argc, 1, 2);
+    key = argv[0];
     block_given = rb_block_given_p();
     if (block_given && argc == 2) {
 	rb_warn("block supersedes default value argument");
@@ -2653,7 +2657,7 @@ env_fetch(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/hash.c#L2657
 	if (argc == 1) {
 	    rb_raise(rb_eKeyError, "key not found: \"%"PRIsVALUE"\"", key);
 	}
-	return if_none;
+	return argv[1];
     }
     if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env))
 	return env_path_str_new(env);

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

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