Hello Alex, good point. I remember this has indeed come up in discussions in this forum.
Searching "byte slice string copy" gave (among others) [1] [2] [3] [4] [5] [6] [7]. All of these look related to the suggested optimization "don't allocate© for a []byte to string, or string to []byte, conversion, under certain circumstances". Cheers Val [1] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/m46jaS6bgZg/R5hSOPFz5m0J [2] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/CwoKDOhv6vw/sf35VZOZDQAJ [3] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/ENgbUzYvCuU/gWa8V8wGAwAJ [4] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/ajXzEM6lqJI/vRsqXxizBAAJ [5] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/f2cX-BIJsqY/bzK77xpU8PMJ [6] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/IfILC-wllaI/U8v88T3aBgAJ [7] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/fXmG83gZOJg/eixtKSQiNysJ On Monday, February 13, 2017 at 9:31:06 PM UTC+1, Alex Flint wrote: > > As of go1.8, do conversions between strings and byte slices always > generate a copy? > > I understand the immutability guarantees in the language spec, but I'm > interested in this from an efficiency standpoint. I can imagine a compiler > that analyzes whether a byte slice created from such a conversion is ever > modified and foregoing the copy in some cases, while still adhering to the > immutability guarantees. > > I have searched this forum for a past thread on this topic but have come > up empty. Feel free to point me to the relevant discussion. > > -- 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.