Re: [go-nuts] Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread 'Paul Borman' via golang-nuts
As long as no one modifies the bytes in the byteslice. Go can no longer enforce that the string is immutable with this hack. On Mon, Sep 19, 2016 at 2:35 PM, wrote: > I don't like the extra allocation and copies involved when casting from > byte slice to string or vice

[go-nuts] Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread badrelish
I don't like the extra allocation and copies involved when casting from byte slice to string or vice versa just because one type or the other is required. The code below reuses the data pointer and as far as I can tell in my tests so far, it even works well with garbage collection. My question