mirror of
https://github.com/golang/go
synced 2024-11-19 11:04:47 -07:00
cmd/compile: simplify transformclosure
Use idiomatic slicing operations instead of incrementally building a linked list. Passes toolstash -cmp. Change-Id: Idb0e40c7b4d7d1110d23828afa8ae1d157ba905f Reviewed-on: https://go-review.googlesource.com/20556 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
501b1fc3f2
commit
c7917de0bb
@ -296,20 +296,14 @@ func transformclosure(xfunc *Node) {
|
||||
// f is ONAME of the actual function.
|
||||
f := xfunc.Func.Nname
|
||||
|
||||
// Get pointer to input arguments.
|
||||
// We are going to insert captured variables before input args.
|
||||
param := &f.Type.Params().Type
|
||||
original_args := *param // old input args
|
||||
original_dcl := xfunc.Func.Dcl
|
||||
xfunc.Func.Dcl = nil
|
||||
|
||||
var addr *Node
|
||||
var fld *Type
|
||||
var params []*Type
|
||||
var decls []*Node
|
||||
for _, v := range func_.Func.Cvars.Slice() {
|
||||
if v.Op == OXXX {
|
||||
continue
|
||||
}
|
||||
fld = typ(TFIELD)
|
||||
fld := typ(TFIELD)
|
||||
fld.Funarg = true
|
||||
if v.Name.Byval {
|
||||
// If v is captured by value, we merely downgrade it to PPARAM.
|
||||
@ -322,7 +316,7 @@ func transformclosure(xfunc *Node) {
|
||||
// we introduce function param &v *T
|
||||
// and v remains PPARAMREF with &v heapaddr
|
||||
// (accesses will implicitly deref &v).
|
||||
addr = newname(Lookupf("&%s", v.Sym.Name))
|
||||
addr := newname(Lookupf("&%s", v.Sym.Name))
|
||||
addr.Type = Ptrto(v.Type)
|
||||
addr.Class = PPARAM
|
||||
v.Name.Heapaddr = addr
|
||||
@ -332,14 +326,15 @@ func transformclosure(xfunc *Node) {
|
||||
fld.Type = fld.Nname.Type
|
||||
fld.Sym = fld.Nname.Sym
|
||||
|
||||
// Declare the new param and add it the first part of the input arguments.
|
||||
xfunc.Func.Dcl = append(xfunc.Func.Dcl, fld.Nname)
|
||||
|
||||
*param = fld
|
||||
param = &fld.Down
|
||||
params = append(params, fld)
|
||||
decls = append(decls, fld.Nname)
|
||||
}
|
||||
|
||||
if len(params) > 0 {
|
||||
// Prepend params and decls.
|
||||
f.Type.Params().SetFields(append(params, f.Type.Params().FieldSlice()...))
|
||||
xfunc.Func.Dcl = append(decls, xfunc.Func.Dcl...)
|
||||
}
|
||||
*param = original_args
|
||||
xfunc.Func.Dcl = append(xfunc.Func.Dcl, original_dcl...)
|
||||
|
||||
// Recalculate param offsets.
|
||||
if f.Type.Width > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user