ruby-changes:43910
From: nobu <ko1@a...>
Date: Mon, 22 Aug 2016 13:21:58 +0900 (JST)
Subject: [ruby-changes:43910] nobu:r55983 (trunk): array.c: elements in self
nobu 2016-08-22 13:21:54 +0900 (Mon, 22 Aug 2016) New Revision: 55983 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55983 Log: array.c: elements in self * array.c (rb_ary_splice): consider elements in middle of self. Modified files: trunk/array.c Index: array.c =================================================================== --- array.c (revision 55982) +++ array.c (revision 55983) @@ -1563,7 +1563,7 @@ static void https://github.com/ruby/ruby/blob/trunk/array.c#L1563 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 https://github.com/ruby/ruby/blob/trunk/array.c#L1578 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 https://github.com/ruby/ruby/blob/trunk/array.c#L1592 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 https://github.com/ruby/ruby/blob/trunk/array.c#L1616 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); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/