Code style in golang compiler

110 views
Skip to first unread message

messi...@gmail.com

unread,
Feb 8, 2021, 10:37:29 PM2/8/21
to golang-nuts
Hi,

I'm reading the go compiler source code and found the following code style in several places:

DeepinScreenshot_select-area_20210209105635.png

Is there some special reasons to group n,m,p to a local struct? 

Why don't we just init n the following way:

DeepinScreenshot_select-area_20210209110823.png

Dan Kortschak

unread,
Feb 8, 2021, 10:49:00 PM2/8/21
to golan...@googlegroups.com
On Mon, 2021-02-08 at 19:09 -0800, messi...@gmail.com wrote:
> Hi,
>
> I'm reading the go compiler source code and found the following code
> style in several places:
>
>
>
> Is there some special reasons to group n,m,p to a local struct?
>
> Why don't we just init n the following way:

Maybe because the Node, Name and Param will all be allocated in a
single contiguous allocation in the form that exists in the current
tree.



BTW Please don't post images for source code.


Luke Champine

unread,
Feb 8, 2021, 10:51:16 PM2/8/21
to golang-nuts
git blame is instructive here. The commit in question is: https://github.com/golang/go/commit/166b1219b8a5b246c83986c7ecef3d15c85c8150

I can't claim to fully understand the commit message, but I believe that this change will cause the runtime to allocate both values together, rather than separately, and this slightly reduces GC pressure.

messi...@gmail.com

unread,
Feb 8, 2021, 10:57:39 PM2/8/21
to golang-nuts
Thanks, the commit message explains everything :-)
Reply all
Reply to author
Forward
0 new messages