From 671ce96095252f8c83a779a237cf9d06f2b52fd5 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 22 Aug 2016 04:21:54 +0000 Subject: 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 --- array.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'array.c') 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); } } -- cgit v1.2.3