diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-02-17 17:42:09 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-04-12 22:17:33 +0900 |
commit | 80b537f14c4af699b26e52931ae7e64a547e68c5 (patch) | |
tree | 17dd1e7babde4c90f27a14988a36bd96b6557c28 /gc.c | |
parent | 456523e2ede3073767fd8cb73cc4b159c3608890 (diff) | |
download | ruby-80b537f14c4af699b26e52931ae7e64a547e68c5.tar.gz |
{Enumerable,Array,Range}#first, {Array,Range}#last with blockfeature/enumerable-first-with-block
* array.c (rb_ary_first, ary_last): extend Array#{first,last} to accept
a block. If a block is passed, these methods collects only elements
for which the block returns a truthy value.
* enum.c: extend Enumerable#first to accept a block.
* range.c: extend Range#{first,last} to accept a block.
* gc.c: avoid using rb_ary_last(), because it may call a block.
* test/ruby/test_array.rb: add test
* test/ruby/test_enum.rb: ditto
* test/ruby/test_range.rb: ditto
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -6094,7 +6094,9 @@ void rb_gc_register_mark_object(VALUE obj) { VALUE ary_ary = GET_THREAD()->vm->mark_object_ary; - VALUE ary = rb_ary_last(0, 0, ary_ary); + VALUE ary = Qnil; + if (RARRAY_LEN(ary_ary)) + ary = RARRAY_AREF(ary_ary, RARRAY_LEN(ary_ary) - 1); if (ary == Qnil || RARRAY_LEN(ary) >= MARK_OBJECT_ARY_BUCKET_SIZE) { ary = rb_ary_tmp_new(MARK_OBJECT_ARY_BUCKET_SIZE); |