mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) ec8e5f5aa64e2a54cf1e303f2b012c98e8d521ba,5a187e26adc8aa32367f294c1496935c7356d386: [Backport #15952]
array.c: always check frozenness in Array#unshift. Fixes [Bug #15952]
Closes: https://github.com/ruby/ruby/pull/2251
array.c add back shared array optimization to
ary_ensure_room_for_unshift
Bug fix in commit ec8e5f5aa6 [Bug #15952] disabled an
optimization in this function.
Closes: https://github.com/ruby/ruby/pull/2252
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67771 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
080e04e863
commit
ef626cd09c
3 changed files with 14 additions and 2 deletions
3
array.c
3
array.c
|
|
@ -1118,6 +1118,8 @@ ary_ensure_room_for_unshift(VALUE ary, int argc)
|
||||||
rb_raise(rb_eIndexError, "index %ld too big", new_len);
|
rb_raise(rb_eIndexError, "index %ld too big", new_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb_ary_modify(ary);
|
||||||
|
|
||||||
if (ARY_SHARED_P(ary)) {
|
if (ARY_SHARED_P(ary)) {
|
||||||
VALUE shared = ARY_SHARED(ary);
|
VALUE shared = ARY_SHARED(ary);
|
||||||
capa = RARRAY_LEN(shared);
|
capa = RARRAY_LEN(shared);
|
||||||
|
|
@ -1128,7 +1130,6 @@ ary_ensure_room_for_unshift(VALUE ary, int argc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_ary_modify(ary);
|
|
||||||
capa = ARY_CAPA(ary);
|
capa = ARY_CAPA(ary);
|
||||||
if (capa - (capa >> 6) <= new_len) {
|
if (capa - (capa >> 6) <= new_len) {
|
||||||
ary_double_capa(ary, new_len);
|
ary_double_capa(ary, new_len);
|
||||||
|
|
|
||||||
|
|
@ -1895,6 +1895,17 @@ class TestArray < Test::Unit::TestCase
|
||||||
assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.unshift(@cls[1, 2]))
|
assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.unshift(@cls[1, 2]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_unshift_frozen
|
||||||
|
bug15952 = '[Bug #15952]'
|
||||||
|
assert_raise(FrozenError, bug15952) do
|
||||||
|
a = [1] * 100
|
||||||
|
b = a[4..-1]
|
||||||
|
a.replace([1])
|
||||||
|
b.freeze
|
||||||
|
b.unshift("a")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OR # '|'
|
def test_OR # '|'
|
||||||
assert_equal(@cls[], @cls[] | @cls[])
|
assert_equal(@cls[], @cls[] | @cls[])
|
||||||
assert_equal(@cls[1], @cls[1] | @cls[])
|
assert_equal(@cls[1], @cls[1] | @cls[])
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.5.6"
|
#define RUBY_VERSION "2.5.6"
|
||||||
#define RUBY_RELEASE_DATE "2019-08-27"
|
#define RUBY_RELEASE_DATE "2019-08-27"
|
||||||
#define RUBY_PATCHLEVEL 189
|
#define RUBY_PATCHLEVEL 190
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2019
|
#define RUBY_RELEASE_YEAR 2019
|
||||||
#define RUBY_RELEASE_MONTH 8
|
#define RUBY_RELEASE_MONTH 8
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue