mirror of
https://github.com/golang/go
synced 2024-11-19 14:54:43 -07:00
cmd/compile: remove last manual node copies
When I added the Node.copy method, I converted most of the occurrences but missed a few. One of them, used only for gdata, was an unnecessary copy given that gdata does not modify the node it is passed. No allocation changes in compilebench. Passes toolstash -cmp on std cmd. Change-Id: I7fba5212377b75c6d6b3785e594a30568ff0732e Reviewed-on: https://go-review.googlesource.com/104937 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
7cb7d62950
commit
60fee0153f
@ -1184,9 +1184,8 @@ func setconst(n *Node, v Val) {
|
|||||||
// Ensure n.Orig still points to a semantically-equivalent
|
// Ensure n.Orig still points to a semantically-equivalent
|
||||||
// expression after we rewrite n into a constant.
|
// expression after we rewrite n into a constant.
|
||||||
if n.Orig == n {
|
if n.Orig == n {
|
||||||
var ncopy Node
|
n.Orig = n.copy()
|
||||||
n.Orig = &ncopy
|
n.Orig.Orig = n.Orig
|
||||||
ncopy = *n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*n = Node{
|
*n = Node{
|
||||||
|
@ -472,8 +472,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
|
|||||||
}
|
}
|
||||||
// Closures with no captured variables are globals,
|
// Closures with no captured variables are globals,
|
||||||
// so the assignment can be done at link time.
|
// so the assignment can be done at link time.
|
||||||
n := *l
|
gdata(l, r.Func.Closure.Func.Nname, Widthptr)
|
||||||
gdata(&n, r.Func.Closure.Func.Nname, Widthptr)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
closuredebugruntimecheck(r)
|
closuredebugruntimecheck(r)
|
||||||
@ -504,10 +503,10 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a copy of l to modify while we emit data.
|
// Create a copy of l to modify while we emit data.
|
||||||
n := *l
|
n := l.copy()
|
||||||
|
|
||||||
// Emit itab, advance offset.
|
// Emit itab, advance offset.
|
||||||
gdata(&n, itab, Widthptr)
|
gdata(n, itab, Widthptr)
|
||||||
n.Xoffset += int64(Widthptr)
|
n.Xoffset += int64(Widthptr)
|
||||||
|
|
||||||
// Emit data.
|
// Emit data.
|
||||||
@ -519,10 +518,10 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
|
|||||||
// Copy val directly into n.
|
// Copy val directly into n.
|
||||||
n.Type = val.Type
|
n.Type = val.Type
|
||||||
setlineno(val)
|
setlineno(val)
|
||||||
a := n
|
a := n.copy()
|
||||||
a.Orig = &a
|
a.Orig = a
|
||||||
if !staticassign(&a, val, out) {
|
if !staticassign(a, val, out) {
|
||||||
*out = append(*out, nod(OAS, &a, val))
|
*out = append(*out, nod(OAS, a, val))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Construct temp to hold val, write pointer to temp into n.
|
// Construct temp to hold val, write pointer to temp into n.
|
||||||
@ -533,7 +532,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
|
|||||||
}
|
}
|
||||||
ptr := nod(OADDR, a, nil)
|
ptr := nod(OADDR, a, nil)
|
||||||
n.Type = types.NewPtr(val.Type)
|
n.Type = types.NewPtr(val.Type)
|
||||||
gdata(&n, ptr, Widthptr)
|
gdata(n, ptr, Widthptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user