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

ruby-changes:5180

From: knu <ko1@a...>
Date: Wed, 28 May 2008 18:12:55 +0900 (JST)
Subject: [ruby-changes:5180] Ruby:r16675 (trunk): * array.c (rb_ary_nitems, Init_Array): Axe Array#nitems().

knu	2008-05-28 18:12:28 +0900 (Wed, 28 May 2008)

  New Revision: 16675

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/doc/NEWS
    trunk/test/ruby/test_array.rb

  Log:
    * array.c (rb_ary_nitems, Init_Array): Axe Array#nitems().
      cf. [ruby-dev:34676]-[ruby-dev:34713]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=16675&r2=16674&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16675&r2=16674&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_array.rb?r1=16675&r2=16674&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/doc/NEWS?r1=16675&r2=16674&diff_format=u

Index: array.c
===================================================================
--- array.c	(revision 16674)
+++ array.c	(revision 16675)
@@ -2747,46 +2747,6 @@
 
 /*
  *  call-seq:
- *     array.nitems -> int
- *     array.nitems { |item| block }  -> int
- *  
- *  Returns the number of non-<code>nil</code> elements in _self_.
- *  If a block is given, the elements yielding a true value are
- *  counted.
- *
- *  May be zero.
- *     
- *     [ 1, nil, 3, nil, 5 ].nitems   #=> 3
- *     [5,6,7,8,9].nitems { |x| x % 2 != 0 }  #=> 3
- */
-
-static VALUE
-rb_ary_nitems(VALUE ary)
-{
-    long n = 0;
- 
-    if (rb_block_given_p()) {
-	long i;
-
-	for (i=0; i<RARRAY_LEN(ary); i++) {
-	    VALUE v = RARRAY_PTR(ary)[i];
- 	    if (RTEST(rb_yield(v))) n++;
- 	}
-    }
-    else {
-	VALUE *p = RARRAY_PTR(ary);
-	VALUE *pend = p + RARRAY_LEN(ary);
-
- 	while (p < pend) {
- 	    if (!NIL_P(*p)) n++;
- 	    p++;
- 	}
-    }
-    return LONG2NUM(n);
-}
-
-/*
- *  call-seq:
  *     array.count(obj) -> int
  *     array.count { |item| block }  -> int
  *  
@@ -3519,7 +3479,6 @@
     rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
     rb_define_method(rb_cArray, "flatten", rb_ary_flatten, -1);
     rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1);
-    rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
     rb_define_method(rb_cArray, "count", rb_ary_count, -1);
     rb_define_method(rb_cArray, "shuffle!", rb_ary_shuffle_bang, 0);
     rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0);
Index: doc/NEWS
===================================================================
--- doc/NEWS	(revision 16674)
+++ doc/NEWS	(revision 16675)
@@ -7,6 +7,8 @@
           o Block arguments
           o New semantics for block arguments
           o Block local variables
+    * Array
+          o Array#nitems was removed (use count {|i| i})
     * String
           o No longer an Enumerable
           o ?c semantics
@@ -33,7 +35,6 @@
           o SecurityError
           o Removed Exception#to_str [Ruby2]
     * Array
-          o Array#nitems
           o Array#[m,n] = nil places nil in the array.
     * Hash
           o Hash#to_s is equivalent to Hash#inspect
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16674)
+++ ChangeLog	(revision 16675)
@@ -1,3 +1,8 @@
+Wed May 28 18:05:28 2008  Akinori MUSHA  <knu@i...>
+
+	* array.c (rb_ary_nitems, Init_Array): Axe Array#nitems().
+	  cf. [ruby-dev:34676]-[ruby-dev:34713]
+
 Wed May 28 17:50:32 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/mkexports.rb (Exports#objdump, Exports#each_line): extracted.
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 16674)
+++ test/ruby/test_array.rb	(revision 16675)
@@ -827,14 +827,6 @@
     assert_equal(@cls[], a)
   end
 
-  def test_nitems
-    assert_equal(0, @cls[].nitems)
-    assert_equal(1, @cls[1].nitems)
-    assert_equal(1, @cls[1, nil].nitems)
-    assert_equal(1, @cls[nil, 1].nitems)
-    assert_equal(3, @cls[1, nil, nil, 2, nil, 3, nil].nitems)
-  end
-
   def test_pack
     a = @cls[*%w( cat wombat x yy)]
     assert_equal("catwomx  yy ", a.pack("A3A3A3A3"))
@@ -1513,10 +1505,6 @@
     assert_equal(a.hash, b.hash)
   end
 
-  def test_nitems2
-    assert_equal(3, [5,6,7,8,9].nitems { |x| x % 2 != 0 })
-  end
-
   def test_flatten2
     a = []
     a << a

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

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