summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-22 04:21:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-22 04:21:54 +0000
commit2329d8b0de4417d8cc6eb05d113c25852640de4a (patch)
treeb4b172c50e5314d802fe41eedc089a6d7450e9b7 /array.c
parent7ac136c980ec74bff1a1d9f5d7b5a622a16ee689 (diff)
array.c: elements in self
* array.c (rb_ary_splice): consider elements in middle of self. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/array.c b/array.c
index 60a26d4009..6e0c62070b 100644
--- a/array.c
+++ b/array.c
@@ -1563,7 +1563,7 @@ static void
rb_ary_splice(VALUE ary, long beg, long len, const VALUE *rptr, long rlen)
{
long olen;
- int self_insert;
+ long rofs;
if (len < 0) rb_raise(rb_eIndexError, "negative length (%ld)", len);
olen = RARRAY_LEN(ary);
@@ -1578,7 +1578,10 @@ rb_ary_splice(VALUE ary, long beg, long len, const VALUE *rptr, long rlen)
len = olen - beg;
}
- self_insert = rptr == RARRAY_CONST_PTR(ary);
+ {
+ const VALUE *optr = RARRAY_CONST_PTR(ary);
+ rofs = (rptr >= optr && rptr < optr + olen) ? rptr - optr : -1;
+ }
if (beg >= olen) {
VALUE target_ary;
@@ -1589,7 +1592,7 @@ rb_ary_splice(VALUE ary, long beg, long len, const VALUE *rptr, long rlen)
len = beg + rlen;
ary_mem_clear(ary, olen, beg - olen);
if (rlen > 0) {
- if (self_insert) rptr = RARRAY_CONST_PTR(ary);
+ if (rofs != -1) rptr = RARRAY_CONST_PTR(ary) + rofs;
ary_memcpy0(ary, beg, rlen, rptr, target_ary);
}
ARY_SET_LEN(ary, len);
@@ -1613,7 +1616,7 @@ rb_ary_splice(VALUE ary, long beg, long len, const VALUE *rptr, long rlen)
ARY_SET_LEN(ary, alen);
}
if (rlen > 0) {
- if (self_insert) rptr = RARRAY_CONST_PTR(ary);
+ if (rofs != -1) rptr = RARRAY_CONST_PTR(ary) + rofs;
MEMMOVE(RARRAY_PTR(ary) + beg, rptr, VALUE, rlen);
}
}