[go-nuts] Re: Copying slice over itself

2017-09-07 Thread peterGo
Deepak Jois, Consider this case: The Go Programming Language Specification https://golang.org/ref/spec Slice expressions https://golang.org/ref/spec#Slice_expressions Full slice expressions For an array, pointer to array, or slice a (but not a string), the primary expression a[low : high

Re: [go-nuts] Re: Copying slice over itself

2017-09-07 Thread peterGo
Rob, "Two slices sharing an array will, however, share their last element. Here is a better test, but this is pretty magical stuff: https://play.golang.org/p/SZgpCh9D-l"; a := []int{0, 1, 2, 3, 4, 5, 6, 7} s := a[1:3:5] https://play.golang.org/p/Q

Re: [go-nuts] Re: Copying slice over itself

2017-09-07 Thread Rob Pike
That test is only sufficient if the zeroth elements in the two slices are at the same address, which is often not true: https://play.golang.org/p/TH53Pxt5Do Two slices sharing an array will, however, share their last element. Here is a better test, but this is pretty magical stuff: https://play.go

[go-nuts] Re: Copying slice over itself

2017-09-07 Thread djadala
Hi, Just check if backing array are same before copying: https://play.golang.org/p/MSqs-jRkSO On Thursday, September 7, 2017 at 8:54:16 AM UTC+3, Deepak Jois wrote: > > Hi > > Pls look at this code: https://play.golang.org/p/QfQOo1iyp4 > > I am copying a slice over itself. How does it work inter