Commit c7917de0 authored by Matthew Dempsky's avatar Matthew Dempsky

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/20556Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 501b1fc3
...@@ -296,20 +296,14 @@ func transformclosure(xfunc *Node) { ...@@ -296,20 +296,14 @@ func transformclosure(xfunc *Node) {
// f is ONAME of the actual function. // f is ONAME of the actual function.
f := xfunc.Func.Nname f := xfunc.Func.Nname
// Get pointer to input arguments.
// We are going to insert captured variables before input args. // We are going to insert captured variables before input args.
param := &f.Type.Params().Type var params []*Type
original_args := *param // old input args var decls []*Node
original_dcl := xfunc.Func.Dcl
xfunc.Func.Dcl = nil
var addr *Node
var fld *Type
for _, v := range func_.Func.Cvars.Slice() { for _, v := range func_.Func.Cvars.Slice() {
if v.Op == OXXX { if v.Op == OXXX {
continue continue
} }
fld = typ(TFIELD) fld := typ(TFIELD)
fld.Funarg = true fld.Funarg = true
if v.Name.Byval { if v.Name.Byval {
// If v is captured by value, we merely downgrade it to PPARAM. // If v is captured by value, we merely downgrade it to PPARAM.
...@@ -322,7 +316,7 @@ func transformclosure(xfunc *Node) { ...@@ -322,7 +316,7 @@ func transformclosure(xfunc *Node) {
// we introduce function param &v *T // we introduce function param &v *T
// and v remains PPARAMREF with &v heapaddr // and v remains PPARAMREF with &v heapaddr
// (accesses will implicitly deref &v). // (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.Type = Ptrto(v.Type)
addr.Class = PPARAM addr.Class = PPARAM
v.Name.Heapaddr = addr v.Name.Heapaddr = addr
...@@ -332,14 +326,15 @@ func transformclosure(xfunc *Node) { ...@@ -332,14 +326,15 @@ func transformclosure(xfunc *Node) {
fld.Type = fld.Nname.Type fld.Type = fld.Nname.Type
fld.Sym = fld.Nname.Sym fld.Sym = fld.Nname.Sym
// Declare the new param and add it the first part of the input arguments. params = append(params, fld)
xfunc.Func.Dcl = append(xfunc.Func.Dcl, fld.Nname) decls = append(decls, fld.Nname)
}
*param = fld if len(params) > 0 {
param = &fld.Down // 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. // Recalculate param offsets.
if f.Type.Width > 0 { if f.Type.Width > 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment