From 6e8eea7abe958e7323e0941687ca2e917426d681 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 3 Nov 2007 14:07:48 +0000 Subject: * hash.c (rb_hash_each_pair): make Hash#each to be alias to Hash#each_pair for compatibility and clarity. * hash.c (env_each_pair): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ hash.c | 70 +++++++++------------------------------------------------------ version.h | 6 +++--- 3 files changed, 20 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2767555352..f7404bfe4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Nov 3 22:49:37 2007 Yukihiro Matsumoto + + * hash.c (rb_hash_each_pair): make Hash#each to be alias to + Hash#each_pair for compatibility and clarity. + + * hash.c (env_each_pair): ditto. + Sat Nov 3 22:41:05 2007 Tanaka Akira * configure.in: --with-vendor-hdrdir implemented. diff --git a/hash.c b/hash.c index 821bfcbb8a..385e056248 100644 --- a/hash.c +++ b/hash.c @@ -1082,39 +1082,6 @@ rb_hash_each_key(VALUE hash) static int each_pair_i(VALUE key, VALUE value) -{ - if (key == Qundef) return ST_CONTINUE; - rb_yield_values(2, key, value); - return ST_CONTINUE; -} - -/* - * call-seq: - * hsh.each_pair {| key_value_array | block } -> hsh - * - * Calls block once for each key in hsh, passing the - * key and value to the block as a two-element array. - * - * h = { "a" => 100, "b" => 200 } - * h.each_pair {|(key, value)| puts "#{key} is #{value}" } - * - * produces: - * - * a is 100 - * b is 200 - * - */ - -static VALUE -rb_hash_each_pair(VALUE hash) -{ - RETURN_ENUMERATOR(hash, 0, 0); - rb_hash_foreach(hash, each_pair_i, 0); - return hash; -} - -static int -each_i(VALUE key, VALUE value) { if (key == Qundef) return ST_CONTINUE; rb_yield(rb_assoc_new(key, value)); @@ -1124,10 +1091,10 @@ each_i(VALUE key, VALUE value) /* * call-seq: * hsh.each {| key, value | block } -> hsh + * hsh.each_pair {| key, value | block } -> hsh * * Calls block once for each key in hsh, passing the key-value - * pair as parameters. Also see Hash#each_pair, which - * passes the key and value to the block as a two-element array. + * pair as parameters. * * h = { "a" => 100, "b" => 200 } * h.each {|key, value| puts "#{key} is #{value}" } @@ -1140,10 +1107,10 @@ each_i(VALUE key, VALUE value) */ static VALUE -rb_hash_each(VALUE hash) +rb_hash_each_pair(VALUE hash) { RETURN_ENUMERATOR(hash, 0, 0); - rb_hash_foreach(hash, each_i, 0); + rb_hash_foreach(hash, each_pair_i, 0); return hash; } @@ -2134,12 +2101,14 @@ env_each_value(VALUE ehash) } static VALUE -env_each_i(VALUE ehash, int values) +env_each_pair(VALUE ehash) { char **env; VALUE ary; long i; + RETURN_ENUMERATOR(ehash, 0, 0); + rb_secure(4); ary = rb_ary_new(); env = GET_ENVIRON(environ); @@ -2154,30 +2123,11 @@ env_each_i(VALUE ehash, int values) FREE_ENVIRON(environ); for (i=0; i