On Wednesday, April 17, 2019 at 10:55:10 AM UTC-4, T L wrote: > > For a byte slice with a negative cap, when the followings happen, > a duplication should be performed and its cap should be changed to > positive: > * the elements of the slices are modified > * the slice is assigned to another slice, > * another slice is derived from the slice. > * the slice is used as the first argument of an append call and the number > of appended elements is zero. (an assignment in fact) >
In fact, if, after the latter three operations, if the slice converted from a string is not used nay more, the duplication still needn't to be made. > > > On Wednesday, April 17, 2019 at 4:11:50 AM UTC-4, T L wrote: >> >> The cap of the result slice of []byte(aString) is set to -realCap >> initially. >> An negative cap indicates the elements of the slice shouldn't be modified. >> When a modification operation on the result slice is encountered later, >> a duplication is performed and the cap of the slice is set to realCap. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.