Or look at the source of bytes.Equal() first. :)

https://golang.org/src/bytes/bytes.go?s=505:533#L8

Ren


On Sunday, 17 November 2019 17:54:47 UTC, Kevin Malachowski wrote:
>
> 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.w...@googlemail.com 
> <javascript:>> wrote:
>
>> On Sun, Nov 17, 2019 at 1:00 AM Kevin Malachowski <nifta...@gmail.com 
>> <javascript:>> 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 golan...@googlegroups.com <javascript:>.
>>> 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/3bd2d434-4c45-42a9-b138-42d133c9168d%40googlegroups.com.

Reply via email to