Re: [go-nuts] efficiency of string <-> []byte conversion

2017-02-14 Thread martisch
some more uses: string([]byte): // Some internal compiler optimizations use this function. // - Used for m[string(k)] lookup where m is a string-keyed map and k is a []byte. // - Used for "<"+string(b)+">" concatenation where b is []byte. // - Used for string(b)=="foo" comparison where b is

Re: [go-nuts] efficiency of string <-> []byte conversion

2017-02-13 Thread Ian Lance Taylor
On Mon, Feb 13, 2017 at 12:31 PM, Alex Flint wrote: > > As of go1.8, do conversions between strings and byte slices always generate > a copy? Usually but not absolutely always. The gc compiler has an optimization for map lookups. For a map[string]T, when s is a []byte,

[go-nuts] efficiency of string <-> []byte conversion

2017-02-13 Thread Alex Flint
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