Good call, I don't know why I didn't think of the stack allocation.

The conversion to string first is also quite interesting. If bytes.Equal is
inlined in practice, profiling is probably the only way to tell which is
faster.




On Sun, Nov 17, 2019, 2:48 AM Axel Wagner <axel.wagner...@googlemail.com>
wrote:

> On Sun, Nov 17, 2019 at 1:00 AM Kevin Malachowski <niftasti...@gmail.com>
> wrote:
>
>> "make"ing a byre slice every time you call Equal is not likely as
>> efficient; surely it will put pressure on the garbage collector, assuming
>> it's not just called a few times.
>>
>
> AFAICT the compiler correctly deduces that the slice doesn't escape and
> puts it on the stack. So, no, it doesn't :)
>
>
>>
>> Writing something in less lines is not strictly better. I'd probably just
>> make package level variable and reuse it among multiple calls to that
>> function.
>>
>> --
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/9cfa25b8-4a18-47ca-9f37-5d5ae5b71849%40googlegroups.com
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAPOrGrkJQXfqMmi%3Dbyx63CHNg-0%2BHSmvEOuqHSw%2B8mWQToj%3DPg%40mail.gmail.com.

Reply via email to