mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
array.c: use shared array in rb_ary_slice
* array.c (rb_ary_splice): use shared array in rb_ary_slice. [Feature #6638] - use ary_ensure_room_for_push when rb_ary_slice used to add at the end of array, cause rb_ary_concat use rb_ary_slice. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b11975dfe0
commit
aaa9cb1ab4
2 changed files with 8 additions and 5 deletions
|
@ -1,4 +1,9 @@
|
||||||
Fri Nov 9 16:08:39 2012 Sokolov Yura funny-falcon <funny.falcon@gmail.com>
|
Fri Nov 9 16:08:43 2012 Sokolov Yura funny-falcon <funny.falcon@gmail.com>
|
||||||
|
|
||||||
|
* array.c (rb_ary_splice): use shared array in rb_ary_slice.
|
||||||
|
[Feature #6638]
|
||||||
|
- use ary_ensure_room_for_push when rb_ary_slice used to add at the
|
||||||
|
end of array, cause rb_ary_concat use rb_ary_slice.
|
||||||
|
|
||||||
* array.c (ary_ensure_room_for_push): make array really suitable for
|
* array.c (ary_ensure_room_for_push): make array really suitable for
|
||||||
queue. [Feature #6638]
|
queue. [Feature #6638]
|
||||||
|
|
6
array.c
6
array.c
|
@ -1388,15 +1388,12 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
|
||||||
rpl = rb_ary_to_ary(rpl);
|
rpl = rb_ary_to_ary(rpl);
|
||||||
rlen = RARRAY_LEN(rpl);
|
rlen = RARRAY_LEN(rpl);
|
||||||
}
|
}
|
||||||
rb_ary_modify(ary);
|
|
||||||
if (beg >= RARRAY_LEN(ary)) {
|
if (beg >= RARRAY_LEN(ary)) {
|
||||||
if (beg > ARY_MAX_SIZE - rlen) {
|
if (beg > ARY_MAX_SIZE - rlen) {
|
||||||
rb_raise(rb_eIndexError, "index %ld too big", beg);
|
rb_raise(rb_eIndexError, "index %ld too big", beg);
|
||||||
}
|
}
|
||||||
|
ary_ensure_room_for_push(ary, rlen);
|
||||||
len = beg + rlen;
|
len = beg + rlen;
|
||||||
if (len >= ARY_CAPA(ary)) {
|
|
||||||
ary_double_capa(ary, len);
|
|
||||||
}
|
|
||||||
rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), beg - RARRAY_LEN(ary));
|
rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), beg - RARRAY_LEN(ary));
|
||||||
if (rlen > 0) {
|
if (rlen > 0) {
|
||||||
MEMCPY(RARRAY_PTR(ary) + beg, RARRAY_PTR(rpl), VALUE, rlen);
|
MEMCPY(RARRAY_PTR(ary) + beg, RARRAY_PTR(rpl), VALUE, rlen);
|
||||||
|
@ -1406,6 +1403,7 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
|
||||||
else {
|
else {
|
||||||
long alen;
|
long alen;
|
||||||
|
|
||||||
|
rb_ary_modify(ary);
|
||||||
alen = RARRAY_LEN(ary) + rlen - len;
|
alen = RARRAY_LEN(ary) + rlen - len;
|
||||||
if (alen >= ARY_CAPA(ary)) {
|
if (alen >= ARY_CAPA(ary)) {
|
||||||
ary_double_capa(ary, alen);
|
ary_double_capa(ary, alen);
|
||||||
|
|
Loading…
Reference in a new issue