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

ruby-changes:4515

From: ko1@a...
Date: Mon, 14 Apr 2008 17:57:41 +0900 (JST)
Subject: [ruby-changes:4515] knu - Ruby:r16008 (ruby_1_8): * array.c (rb_ary_collect_bang, rb_ary_select): Return an

knu	2008-04-14 17:57:23 +0900 (Mon, 14 Apr 2008)

  New Revision: 16008

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/NEWS
    branches/ruby_1_8/array.c
    branches/ruby_1_8/dir.c
    branches/ruby_1_8/enum.c
    branches/ruby_1_8/gc.c
    branches/ruby_1_8/hash.c
    branches/ruby_1_8/numeric.c

  Log:
    * array.c (rb_ary_collect_bang, rb_ary_select): Return an
      enumerator if no block is given.
    
    * dir.c (dir_each, dir_foreach): Return an enumerator if no block
      is given.
    
    * enum.c (enum_partition, enum_sort_by): Ditto.
    
    * gc.c (os_each_obj): Ditto.
    
    * hash.c (rb_hash_delete_if, rb_hash_reject_bang, rb_hash_select,
      rb_hash_each_value, rb_hash_each_key, rb_hash_each_pair,
      env_each_key, env_each_value, env_each, env_each_pair,
      env_reject_bang, env_delete_if, env_select): Ditto.
    
    * numeric.c (num_step, int_upto, int_downto, int_dotimes): Ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/enum.c?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/numeric.c?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/dir.c?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/hash.c?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/array.c?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16008&r2=16007&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/gc.c?r1=16008&r2=16007&diff_format=u

Index: ruby_1_8/array.c
===================================================================
--- ruby_1_8/array.c	(revision 16007)
+++ ruby_1_8/array.c	(revision 16008)
@@ -1853,6 +1853,7 @@
 {
     long i;
 
+    RETURN_ENUMERATOR(ary, 0, 0);
     rb_ary_modify(ary);
     for (i = 0; i < RARRAY(ary)->len; i++) {
 	rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
@@ -1937,6 +1938,7 @@
     VALUE result;
     long i;
 
+    RETURN_ENUMERATOR(ary, 0, 0);
     result = rb_ary_new2(RARRAY(ary)->len);
     for (i = 0; i < RARRAY(ary)->len; i++) {
 	if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
Index: ruby_1_8/hash.c
===================================================================
--- ruby_1_8/hash.c	(revision 16007)
+++ ruby_1_8/hash.c	(revision 16008)
@@ -817,6 +817,7 @@
 rb_hash_delete_if(hash)
     VALUE hash;
 {
+    RETURN_ENUMERATOR(hash, 0, 0);
     rb_hash_modify(hash);
     rb_hash_foreach(hash, delete_if_i, hash);
     return hash;
@@ -834,7 +835,10 @@
 rb_hash_reject_bang(hash)
     VALUE hash;
 {
-    int n = RHASH(hash)->tbl->num_entries;
+    int n;
+
+    RETURN_ENUMERATOR(hash, 0, 0);
+    n = RHASH(hash)->tbl->num_entries;
     rb_hash_delete_if(hash);
     if (n == RHASH(hash)->tbl->num_entries) return Qnil;
     return hash;
@@ -912,6 +916,7 @@
 {
     VALUE result;
 
+    RETURN_ENUMERATOR(hash, 0, 0);
     result = rb_ary_new();
     rb_hash_foreach(hash, select_i, result);
     return result;
@@ -1090,6 +1095,7 @@
 rb_hash_each_value(hash)
     VALUE hash;
 {
+    RETURN_ENUMERATOR(hash, 0, 0);
     rb_hash_foreach(hash, each_value_i, 0);
     return hash;
 }
@@ -1122,6 +1128,7 @@
 rb_hash_each_key(hash)
     VALUE hash;
 {
+    RETURN_ENUMERATOR(hash, 0, 0);
     rb_hash_foreach(hash, each_key_i, 0);
     return hash;
 }
@@ -1156,6 +1163,7 @@
 rb_hash_each_pair(hash)
     VALUE hash;
 {
+    RETURN_ENUMERATOR(hash, 0, 0);
     rb_hash_foreach(hash, each_pair_i, 0);
     return hash;
 }
@@ -2003,6 +2011,7 @@
     VALUE keys = env_keys();
     long i;
 
+    RETURN_ENUMERATOR(ehash, 0, 0);
     for (i=0; i<RARRAY(keys)->len; i++) {
 	rb_yield(RARRAY(keys)->ptr[i]);
     }
@@ -2034,6 +2043,7 @@
     VALUE values = env_values();
     long i;
 
+    RETURN_ENUMERATOR(ehash, 0, 0);
     for (i=0; i<RARRAY(values)->len; i++) {
 	rb_yield(RARRAY(values)->ptr[i]);
     }
@@ -2075,6 +2085,7 @@
 env_each(ehash)
     VALUE ehash;
 {
+    RETURN_ENUMERATOR(ehash, 0, 0);
     return env_each_i(ehash, Qfalse);
 }
 
@@ -2086,12 +2097,14 @@
 }
 
 static VALUE
-env_reject_bang()
+env_reject_bang(ehash)
+    VALUE ehash;
 {
     volatile VALUE keys;
     long i;
     int del = 0;
 
+    RETURN_ENUMERATOR(ehash, 0, 0);
     rb_secure(4);
     keys = env_keys();
 
@@ -2110,9 +2123,10 @@
 }
 
 static VALUE
-env_delete_if()
+env_delete_if(ehash)
+    VALUE ehash;
 {
-    env_reject_bang();
+    env_reject_bang(ehash);
     return envtbl;
 }
 
@@ -2131,11 +2145,13 @@
 }
 
 static VALUE
-env_select()
+env_select(ehash)
+    VALUE ehash;
 {
     VALUE result;
     char **env;
 
+    RETURN_ENUMERATOR(ehash, 0, 0);
     result = rb_ary_new();
     env = GET_ENVIRON(environ);
     while (*env) {
Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS	(revision 16007)
+++ ruby_1_8/NEWS	(revision 16008)
@@ -26,6 +26,8 @@
 
     Take a block instead of an argument.
 
+  * Array#collect!
+  * Array#map!
   * Array#each
   * Array#each_index
   * Array#reverse_each
@@ -41,6 +43,11 @@
     Take an optional argument specifying the number of elements to
     remove.
 
+  * Dir#each
+  * Dir#foreach
+
+    Return an enumerator if no block is given.
+
   * Enumerable::Enumerator
 
     New class for various enumeration defined by the enumerator library.
@@ -54,20 +61,60 @@
 
     New methods for various enumeration defined by the enumerator library.
 
-  * Enumerator#count
+  * Enumerable#count
   * Enumerable#find_index
   * Enumerable#first
   * Enumerable#group_by
 
     New methods.
 
-  * Integer#ord implemented.
-  * Integer#odd? implemented.
-  * Integer#even? implemented.
-  * Integer#pred implemented.
+  * Enumerable#find_all
+  * Enumerable#partition
+  * Enumerable#select
+  * Enumerable#sort_by
 
+    Return an enumerator if no block is given.
+
+  * Hash#delete_if
+  * Hash#each
+  * Hash#each_key
+  * Hash#each_pair
+  * Hash#each_value
+  * Hash#reject!
+  * Hash#select
+  * ENV.delete_if
+  * ENV.each
+  * ENV.each_key
+  * ENV.each_pair
+  * ENV.each_value
+  * ENV.reject!
+  * ENV.select
+
+    Return an enumerator if no block is given.
+
+  * Integer#ord
+  * Integer#odd?
+  * Integer#even?
+  * Integer#pred
+
+    New methods.
+
+  * Integer#downto
+  * Integer#times
+  * Integer#upto
+
+    Return an enumerator if no block is given.
+
+  * Numeric#step
+
+    Return an enumerator if no block is given.
+
   * Object#tap implemented.
 
+  * ObjectSpace.each_object
+
+    Return an enumerator if no block is given.
+
   * Process.exec implemented.
 
   * Range#each
Index: ruby_1_8/numeric.c
===================================================================
--- ruby_1_8/numeric.c	(revision 16007)
+++ ruby_1_8/numeric.c	(revision 16008)
@@ -1463,6 +1463,8 @@
 {
     VALUE to, step;
 
+    RETURN_ENUMERATOR(from, argc, argv);
+
     if (argc == 1) {
 	to = argv[0];
 	step = INT2FIX(1);
@@ -2845,6 +2847,8 @@
 int_upto(from, to)
     VALUE from, to;
 {
+    RETURN_ENUMERATOR(from, 1, &to);
+
     if (FIXNUM_P(from) && FIXNUM_P(to)) {
 	long i, end;
 
@@ -2884,6 +2888,8 @@
 int_downto(from, to)
     VALUE from, to;
 {
+    RETURN_ENUMERATOR(from, 1, &to);
+
     if (FIXNUM_P(from) && FIXNUM_P(to)) {
 	long i, end;
 
@@ -2924,6 +2930,8 @@
 int_dotimes(num)
     VALUE num;
 {
+    RETURN_ENUMERATOR(num, 0, 0);
+
     if (FIXNUM_P(num)) {
 	long i, end;
 
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 16007)
+++ ruby_1_8/ChangeLog	(revision 16008)
@@ -1,3 +1,22 @@
+Mon Apr 14 17:55:30 2008  Akinori MUSHA  <knu@i...>
+
+	* array.c (rb_ary_collect_bang, rb_ary_select): Return an
+	  enumerator if no block is given.
+
+	* dir.c (dir_each, dir_foreach): Return an enumerator if no block
+	  is given.
+
+	* enum.c (enum_partition, enum_sort_by): Ditto.
+
+	* gc.c (os_each_obj): Ditto.
+
+	* hash.c (rb_hash_delete_if, rb_hash_reject_bang, rb_hash_select,
+	  rb_hash_each_value, rb_hash_each_key, rb_hash_each_pair,
+	  env_each_key, env_each_value, env_each, env_each_pair,
+	  env_reject_bang, env_delete_if, env_select): Ditto.
+
+	* numeric.c (num_step, int_upto, int_downto, int_dotimes): Ditto.
+
 Mon Apr 14 16:42:53 2008  Akinori MUSHA  <knu@i...>
 
 	* ruby.h (rb_block_call_func): Fix prototype.
Index: ruby_1_8/enum.c
===================================================================
--- ruby_1_8/enum.c	(revision 16007)
+++ ruby_1_8/enum.c	(revision 16008)
@@ -330,7 +330,8 @@
     VALUE obj;
 {
     VALUE ary = rb_ary_new();
-    
+
+    RETURN_ENUMERATOR(obj, 0, 0);
     rb_iterate(rb_each, obj, find_all_i, ary);
 
     return ary;
@@ -521,6 +522,8 @@
 {
     VALUE ary[2];
 
+    RETURN_ENUMERATOR(obj, 0, 0);
+
     ary[0] = rb_ary_new();
     ary[1] = rb_ary_new();
     rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
@@ -759,6 +762,8 @@
     VALUE ary;
     long i;
 
+    RETURN_ENUMERATOR(obj, 0, 0);
+
     if (TYPE(obj) == T_ARRAY) {
 	ary  = rb_ary_new2(RARRAY(obj)->len);
     }
Index: ruby_1_8/dir.c
===================================================================
--- ruby_1_8/dir.c	(revision 16007)
+++ ruby_1_8/dir.c	(revision 16008)
@@ -562,6 +562,7 @@
     struct dir_data *dirp;
     struct dirent *dp;
 
+    RETURN_ENUMERATOR(dir, 0, 0);
     GetDIR(dir, dirp);
     rewinddir(dirp->dir);
     for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
@@ -1814,6 +1815,7 @@
 {
     VALUE dir;
 
+    RETURN_ENUMERATOR(io, 1, &dirname);
     dir = dir_open_dir(dirname);
     rb_ensure(dir_each, dir, dir_close, dir);
     return Qnil;
Index: ruby_1_8/gc.c
===================================================================
--- ruby_1_8/gc.c	(revision 16007)
+++ ruby_1_8/gc.c	(revision 16008)
@@ -1669,16 +1669,21 @@
  */
 
 static VALUE
-os_each_obj(argc, argv)
+os_each_obj(argc, argv, os)
     int argc;
     VALUE *argv;
+    VALUE os;
 {
     VALUE of;
 
     rb_secure(4);
-    if (rb_scan_args(argc, argv, "01", &of) == 0) {
+    if (argc == 0) {
 	of = 0;
     }
+    else {
+	rb_scan_args(argc, argv, "01", &of);
+    }
+    RETURN_ENUMERATOR(os, 1, &of);
     return os_obj_of(of);
 }
 

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

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