Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-12 Thread David Finkel
On Sat, Sep 12, 2020 at 4:25 AM 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hi y'all, > > given that the concern here seems to be performance (though, TBH, I doubt > this particular case is much of a bottleneck), this seems to be far simpler > to address as a compiler

Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-12 Thread 'Axel Wagner' via golang-nuts
Hi y'all, given that the concern here seems to be performance (though, TBH, I doubt this particular case is much of a bottleneck), this seems to be far simpler to address as a compiler optimization - if the compiler can prove there are no other references to a `[]byte`, it can do the conversion

Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-12 Thread tapi...@gmail.com
There is a prerequisite to transfer ownership: it must be proved that no other values share ownership of the byte slice returned by ioutil.ReadFile. On Saturday, September 12, 2020 at 3:42:14 AM UTC-4 tapi...@gmail.com wrote: > Is it good to introduce owner transfer based string<->[]byte

Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-12 Thread tapi...@gmail.com
Is it good to introduce owner transfer based string<->[]byte conversions? After the conversion, the being converted string/[]byte values mustn't be used any more. Such as tlsCertData, _ = ioutil.ReadFile("/etc/ssl/mycert") var tlsCert string = bultin.ByteSlice2String(tlsCertData) // forbid

Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Kevin Chadwick
On 2020-09-11 19:08, Ian Lance Taylor wrote: > The way Go works, ioutil.ReadFile is compiled with the io/ioutil > package. It can't change based on how it is called. So it is always > going to return []byte. Ok. I figured it might save an allocation as well if the coder made clear their

Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Ian Lance Taylor
On Fri, Sep 11, 2020 at 9:45 AM Kevin Chadwick wrote: > > I apologise if this has already been discussed. Google didn't turn up anything > directly related. > > If you read a file using the following that returns a byte slice. > > tlsCertb, err := ioutil.ReadFile("/etc/ssl/mycert") > if err !=

[go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Kevin Chadwick
I apologise if this has already been discussed. Google didn't turn up anything directly related. If you read a file using the following that returns a byte slice. tlsCertb, err := ioutil.ReadFile("/etc/ssl/mycert") if err != nil { log.Fatal(err) } tlsCert = string(tlsCertb) Is there a way to