]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: fix potential closure waste in Order
authorRuss Cox <rsc@golang.org>
Mon, 7 Dec 2020 21:07:38 +0000 (16:07 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 17 Dec 2020 03:49:57 +0000 (03:49 +0000)
I haven't measured this, but it's the only use of EditChildren
where we aren't careful to allocate a closure once and use it
for the whole recursion. This one is allocating a closure at
every level of the recursion, and it was an oversight that it
wasn't cleaned up in the original CL.

Passes buildall w/ toolstash -cmp.

Change-Id: I5e3f1795c6f64c5867a19c077f797643aa1066a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/277914
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/order.go

index fe6473885610798998f060caac69059824e7c87b..e0c0cabcde3ffe7741ced3a4099e6eba628ad852 100644 (file)
@@ -47,6 +47,7 @@ type Order struct {
        out  []ir.Node             // list of generated statements
        temp []*ir.Name            // stack of temporary variables
        free map[string][]*ir.Name // free list of unused temporaries, by type.LongString().
+       edit func(ir.Node) ir.Node // cached closure of o.exprNoLHS
 }
 
 // Order rewrites fn.Nbody to apply the ordering constraints
@@ -1072,7 +1073,10 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
 
        switch n.Op() {
        default:
-               ir.EditChildren(n, o.exprNoLHS)
+               if o.edit == nil {
+                       o.edit = o.exprNoLHS // create closure once
+               }
+               ir.EditChildren(n, o.edit)
 
        // Addition of strings turns into a function call.
        // Allocate a temporary to hold the strings.