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

ruby-changes:2318

From: ko1@a...
Date: 3 Nov 2007 23:23:56 +0900
Subject: [ruby-changes:2318] matz - Ruby:r13809 (trunk): * hash.c (rb_hash_each_pair): make Hash#each to be alias to

matz	2007-11-03 23:07:48 +0900 (Sat, 03 Nov 2007)

  New Revision: 13809

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/version.h

  Log:
    * 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.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=13809&r2=13808
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/hash.c?r1=13809&r2=13808
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13809&r2=13808

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13808)
+++ ChangeLog	(revision 13809)
@@ -1,3 +1,10 @@
+Sat Nov  3 22:49:37 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* 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  <akr@f...>
 
 	* configure.in: --with-vendor-hdrdir implemented.
Index: hash.c
===================================================================
--- hash.c	(revision 13808)
+++ hash.c	(revision 13809)
@@ -1084,39 +1084,6 @@
 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 <i>block</i> once for each key in <i>hsh</i>, 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}" }
- *
- *  <em>produces:</em>
- *
- *     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));
     return ST_CONTINUE;
 }
@@ -1124,10 +1091,10 @@
 /*
  *  call-seq:
  *     hsh.each {| key, value | block } -> hsh
+ *     hsh.each_pair {| key, value | block } -> hsh
  *
  *  Calls <i>block</i> once for each key in <i>hsh</i>, passing the key-value
- *  pair as parameters.  Also see <code>Hash#each_pair</code>, 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 @@
  */
 
 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 @@
 }
 
 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,31 +2123,12 @@
     FREE_ENVIRON(environ);
 
     for (i=0; i<RARRAY_LEN(ary); i+=2) {
-	if (values) {
-	    rb_yield_values(2, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]);
-	}
-	else {
-	    rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]));
-	}
+	rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]));
     }
     return ehash;
 }
 
 static VALUE
-env_each(VALUE ehash)
-{
-    RETURN_ENUMERATOR(ehash, 0, 0);
-    return env_each_i(ehash, Qtrue);
-}
-
-static VALUE
-env_each_pair(VALUE ehash)
-{
-    RETURN_ENUMERATOR(ehash, 0, 0);
-    return env_each_i(ehash, Qfalse);
-}
-
-static VALUE
 env_reject_bang(void)
 {
     volatile VALUE keys;
@@ -2622,10 +2572,10 @@
     rb_define_method(rb_cHash,"length", rb_hash_size, 0);
     rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);
 
-    rb_define_method(rb_cHash,"each", rb_hash_each, 0);
     rb_define_method(rb_cHash,"each_value", rb_hash_each_value, 0);
     rb_define_method(rb_cHash,"each_key", rb_hash_each_key, 0);
     rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0);
+    rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
 
     rb_define_method(rb_cHash,"keys", rb_hash_keys, 0);
     rb_define_method(rb_cHash,"values", rb_hash_values, 0);
@@ -2666,7 +2616,7 @@
     rb_define_singleton_method(envtbl,"fetch", env_fetch, -1);
     rb_define_singleton_method(envtbl,"[]=", env_aset, 2);
     rb_define_singleton_method(envtbl,"store", env_aset, 2);
-    rb_define_singleton_method(envtbl,"each", env_each, 0);
+    rb_define_singleton_method(envtbl,"each", env_each_pair, 0);
     rb_define_singleton_method(envtbl,"each_pair", env_each_pair, 0);
     rb_define_singleton_method(envtbl,"each_key", env_each_key, 0);
     rb_define_singleton_method(envtbl,"each_value", env_each_value, 0);
Index: version.h
===================================================================
--- version.h	(revision 13808)
+++ version.h	(revision 13809)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2007-11-02"
+#define RUBY_RELEASE_DATE "2007-11-03"
 #define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20071102
+#define RUBY_RELEASE_CODE 20071103
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 0
 #define RUBY_RELEASE_YEAR 2007
 #define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 2
+#define RUBY_RELEASE_DAY 3
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];

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

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