ruby-changes:38127
From: ko1 <ko1@a...>
Date: Fri, 10 Apr 2015 19:13:19 +0900 (JST)
Subject: [ruby-changes:38127] ko1:r50208 (trunk): * ext/objspace/objspace.c (setup_hash): unify common routine.
ko1 2015-04-10 19:13:00 +0900 (Fri, 10 Apr 2015) New Revision: 50208 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50208 Log: * ext/objspace/objspace.c (setup_hash): unify common routine. Modified files: trunk/ChangeLog trunk/ext/objspace/objspace.c Index: ChangeLog =================================================================== --- ChangeLog (revision 50207) +++ ChangeLog (revision 50208) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Apr 10 19:10:34 2015 Koichi Sasada <ko1@a...> + + * ext/objspace/objspace.c (setup_hash): unify common routine. + Fri Apr 10 18:29:49 2015 Tanaka Akira <akr@f...> * process.c (rb_execarg_parent_start1): Handle EINTR. Index: ext/objspace/objspace.c =================================================================== --- ext/objspace/objspace.c (revision 50207) +++ ext/objspace/objspace.c (revision 50208) @@ -125,6 +125,26 @@ set_zero_i(st_data_t key, st_data_t val, https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L125 return ST_CONTINUE; } +static VALUE +setup_hash(int argc, VALUE *argv) +{ + VALUE hash; + + if (rb_scan_args(argc, argv, "01", &hash) == 1) { + if (!RB_TYPE_P(hash, T_HASH)) + rb_raise(rb_eTypeError, "non-hash given"); + } + + if (hash == Qnil) { + hash = rb_hash_new(); + } + else if (!RHASH_EMPTY_P(hash)) { + st_foreach(RHASH_TBL(hash), set_zero_i, hash); + } + + return hash; +} + static int cos_i(void *vstart, void *vend, size_t stride, void *data) { @@ -206,12 +226,7 @@ count_objects_size(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L226 size_t counts[T_MASK+1]; size_t total = 0; enum ruby_value_type i; - VALUE hash; - - if (rb_scan_args(argc, argv, "01", &hash) == 1) { - if (!RB_TYPE_P(hash, T_HASH)) - rb_raise(rb_eTypeError, "non-hash given"); - } + VALUE hash = setup_hash(argc, argv); for (i = 0; i <= T_MASK; i++) { counts[i] = 0; @@ -281,12 +296,7 @@ count_nodes(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L296 { size_t nodes[NODE_LAST+1]; size_t i; - VALUE hash; - - if (rb_scan_args(argc, argv, "01", &hash) == 1) { - if (!RB_TYPE_P(hash, T_HASH)) - rb_raise(rb_eTypeError, "non-hash given"); - } + VALUE hash = setup_hash(argc, argv); for (i = 0; i <= NODE_LAST; i++) { nodes[i] = 0; @@ -485,22 +495,8 @@ cto_i(void *vstart, void *vend, size_t s https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L495 static VALUE count_tdata_objects(int argc, VALUE *argv, VALUE self) { - VALUE hash; - - if (rb_scan_args(argc, argv, "01", &hash) == 1) { - if (!RB_TYPE_P(hash, T_HASH)) - rb_raise(rb_eTypeError, "non-hash given"); - } - - if (hash == Qnil) { - hash = rb_hash_new(); - } - else if (!RHASH_EMPTY_P(hash)) { - st_foreach(RHASH_TBL(hash), set_zero_i, hash); - } - + VALUE hash = setup_hash(argc, argv); rb_objspace_each_objects(cto_i, (void *)hash); - return hash; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/