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

ruby-changes:37701

From: nobu <ko1@a...>
Date: Sat, 28 Feb 2015 18:09:31 +0900 (JST)
Subject: [ruby-changes:37701] nobu:r49782 (trunk): enum.c: Fixnum only

nobu	2015-02-28 18:09:18 +0900 (Sat, 28 Feb 2015)

  New Revision: 49782

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49782

  Log:
    enum.c: Fixnum only
    
    * enum.c (limit_by_enum_size, enum_size_over_p): check only
      against Fixnum size.

  Modified files:
    trunk/enum.c
    trunk/test/ruby/test_lazy_enumerator.rb
Index: enum.c
===================================================================
--- enum.c	(revision 49781)
+++ enum.c	(revision 49782)
@@ -319,17 +319,17 @@ limit_by_enum_size(VALUE obj, long n) https://github.com/ruby/ruby/blob/trunk/enum.c#L319
 {
     unsigned long limit;
     VALUE size = rb_check_funcall(obj, id_size, 0, 0);
-    if (size == Qundef) return n;
-    limit = NUM2ULONG(size);
-    return ((unsigned long)n > limit) ? limit : n;
+    if (!FIXNUM_P(size)) return n;
+    limit = FIX2ULONG(size);
+    return ((unsigned long)n > limit) ? (long)limit : n;
 }
 
 static int
 enum_size_over_p(VALUE obj, long n)
 {
     VALUE size = rb_check_funcall(obj, id_size, 0, 0);
-    if (size == Qundef) return 0;
-    return ((unsigned long)n > NUM2ULONG(size));
+    if (!FIXNUM_P(size)) return 0;
+    return ((unsigned long)n > FIX2ULONG(size));
 }
 
 /*
Index: test/ruby/test_lazy_enumerator.rb
===================================================================
--- test/ruby/test_lazy_enumerator.rb	(revision 49781)
+++ test/ruby/test_lazy_enumerator.rb	(revision 49782)
@@ -483,6 +483,18 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L483
     assert_equal Enumerator::Lazy, [].lazy.slice_when{}.class, bug7507
   end
 
+  def test_each_cons_limit
+    n = 1 << 120
+    assert_equal([1, 2], (1..n).lazy.each_cons(2).first)
+    assert_equal([[1, 2], [2, 3]], (1..n).lazy.each_cons(2).first(2))
+  end
+
+  def test_each_slice_limit
+    n = 1 << 120
+    assert_equal([1, 2], (1..n).lazy.each_slice(2).first)
+    assert_equal([[1, 2], [3, 4]], (1..n).lazy.each_slice(2).first(2))
+  end
+
   def test_no_warnings
     le = (1..3).lazy
     assert_warning("") {le.zip([4,5,6]).force}

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

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