1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

array.c: maybe shared array

* array.c (ary_reject): may be turned into a shared array during
  the given block.  [ruby-dev:48101] [Bug #9727]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-04-11 03:44:52 +00:00
parent 48d5eb3d40
commit 153fa25658
3 changed files with 22 additions and 14 deletions

View file

@ -1,3 +1,8 @@
Fri Apr 11 12:44:50 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (ary_reject): may be turned into a shared array during
the given block. [ruby-dev:48101] [Bug #9727]
Thu Apr 10 23:41:21 2014 Akinori MUSHA <knu@iDaemons.org>
* lib/net/ftp.rb (Net::FTP#login): [DOC] The default password for

15
array.c
View file

@ -905,19 +905,6 @@ rb_ary_push(VALUE ary, VALUE item)
return ary;
}
static VALUE
rb_ary_push_1(VALUE ary, VALUE item)
{
long idx = RARRAY_LEN(ary);
if (idx >= ARY_CAPA(ary)) {
ary_double_capa(ary, idx);
}
RARRAY_ASET(ary, idx, item);
ARY_SET_LEN(ary, idx + 1);
return ary;
}
VALUE
rb_ary_cat(VALUE ary, const VALUE *ptr, long len)
{
@ -3084,7 +3071,7 @@ ary_reject(VALUE orig, VALUE result)
for (i = 0; i < RARRAY_LEN(orig); i++) {
VALUE v = RARRAY_AREF(orig, i);
if (!RTEST(rb_yield(v))) {
rb_ary_push_1(result, v);
rb_ary_push(result, v);
}
}
return result;

View file

@ -2011,6 +2011,22 @@ class TestArray < Test::Unit::TestCase
assert_equal([1, 3], [0, 1, 2, 3].reject {|x| x % 2 == 0 })
end
def test_reject_with_callcc
respond_to?(:callcc, true) or require 'continuation'
bug9727 = '[ruby-dev:48101] [Bug #9727]'
cont = nil
a = [*1..10].reject do |i|
callcc {|c| cont = c} if !cont and i == 10
false
end
if a.size < 1000
a.unshift(:x)
cont.call
end
assert_equal(1000, a.size, bug9727)
assert_equal([:x, *1..10], a.uniq, bug9727)
end
def test_zip
assert_equal([[1, :a, "a"], [2, :b, "b"], [3, nil, "c"]],
[1, 2, 3].zip([:a, :b], ["a", "b", "c", "d"]))