@@ -110,8 +110,9 @@ func caninl(fn *Node) {
110
110
111
111
// can't handle ... args yet
112
112
if Debug ['l' ] < 3 {
113
- for _ , t := range fn .Type .Params ().Fields ().Slice () {
114
- if t .Isddd {
113
+ f := fn .Type .Params ().Fields ()
114
+ if len := f .Len (); len > 0 {
115
+ if t := f .Index (len - 1 ); t .Isddd {
115
116
return
116
117
}
117
118
}
@@ -128,35 +129,37 @@ func caninl(fn *Node) {
128
129
}
129
130
130
131
const maxBudget = 80
131
- budget := maxBudget // allowed hairyness
132
+ budget := int32 ( maxBudget ) // allowed hairyness
132
133
if ishairylist (fn .Nbody , & budget ) || budget < 0 {
133
134
return
134
135
}
135
136
136
137
savefn := Curfn
137
138
Curfn = fn
138
139
139
- fn .Func .Nname .Func .Inl .Set (fn .Nbody .Slice ())
140
- fn .Nbody .Set (inlcopylist (fn .Func .Nname .Func .Inl .Slice ()))
141
- inldcl := inlcopylist (fn .Func .Nname .Name .Defn .Func .Dcl )
142
- fn .Func .Nname .Func .Inldcl .Set (inldcl )
143
- fn .Func .Nname .Func .InlCost = int32 (maxBudget - budget )
140
+ n := fn .Func .Nname
141
+
142
+ n .Func .Inl .Set (fn .Nbody .Slice ())
143
+ fn .Nbody .Set (inlcopylist (n .Func .Inl .Slice ()))
144
+ inldcl := inlcopylist (n .Name .Defn .Func .Dcl )
145
+ n .Func .Inldcl .Set (inldcl )
146
+ n .Func .InlCost = maxBudget - budget
144
147
145
148
// hack, TODO, check for better way to link method nodes back to the thing with the ->inl
146
149
// this is so export can find the body of a method
147
- fn .Type .SetNname (fn . Func . Nname )
150
+ fn .Type .SetNname (n )
148
151
149
152
if Debug ['m' ] > 1 {
150
- fmt .Printf ("%v: can inline %v as: %v { %v }\n " , fn .Line (), Nconv (fn . Func . Nname , FmtSharp ), Tconv (fn .Type , FmtSharp ), Hconv (fn . Func . Nname .Func .Inl , FmtSharp ))
153
+ fmt .Printf ("%v: can inline %v as: %v { %v }\n " , fn .Line (), Nconv (n , FmtSharp ), Tconv (fn .Type , FmtSharp ), Hconv (n .Func .Inl , FmtSharp ))
151
154
} else if Debug ['m' ] != 0 {
152
- fmt .Printf ("%v: can inline %v\n " , fn .Line (), fn . Func . Nname )
155
+ fmt .Printf ("%v: can inline %v\n " , fn .Line (), n )
153
156
}
154
157
155
158
Curfn = savefn
156
159
}
157
160
158
161
// Look for anything we want to punt on.
159
- func ishairylist (ll Nodes , budget * int ) bool {
162
+ func ishairylist (ll Nodes , budget * int32 ) bool {
160
163
for _ , n := range ll .Slice () {
161
164
if ishairy (n , budget ) {
162
165
return true
@@ -165,21 +168,21 @@ func ishairylist(ll Nodes, budget *int) bool {
165
168
return false
166
169
}
167
170
168
- func ishairy (n * Node , budget * int ) bool {
171
+ func ishairy (n * Node , budget * int32 ) bool {
169
172
if n == nil {
170
173
return false
171
174
}
172
175
173
176
switch n .Op {
174
177
// Call is okay if inlinable and we have the budget for the body.
175
178
case OCALLFUNC :
176
- if n .Left .Func != nil && n . Left . Func .Inl .Len () != 0 {
177
- * budget -= int ( n . Left . Func . InlCost )
179
+ if fn := n .Left .Func ; fn != nil && fn .Inl .Len () != 0 {
180
+ * budget -= fn . InlCost
178
181
break
179
182
}
180
183
if n .Left .Op == ONAME && n .Left .Left != nil && n .Left .Left .Op == OTYPE && n .Left .Right != nil && n .Left .Right .Op == ONAME { // methods called as functions
181
- if n .Left .Sym .Def != nil && n . Left . Sym . Def .Func .Inl .Len () != 0 {
182
- * budget -= int ( n . Left . Sym . Def . Func .InlCost )
184
+ if d := n .Left .Sym .Def ; d != nil && d .Func .Inl .Len () != 0 {
185
+ * budget -= d . Func .InlCost
183
186
break
184
187
}
185
188
}
@@ -189,14 +192,15 @@ func ishairy(n *Node, budget *int) bool {
189
192
190
193
// Call is okay if inlinable and we have the budget for the body.
191
194
case OCALLMETH :
192
- if n .Left .Type == nil {
195
+ t := n .Left .Type
196
+ if t == nil {
193
197
Fatalf ("no function type for [%p] %v\n " , n .Left , Nconv (n .Left , FmtSign ))
194
198
}
195
- if n . Left . Type .Nname () == nil {
196
- Fatalf ("no function definition for [%p] %v\n " , n . Left . Type , Tconv (n . Left . Type , FmtSign ))
199
+ if t .Nname () == nil {
200
+ Fatalf ("no function definition for [%p] %v\n " , t , Tconv (t , FmtSign ))
197
201
}
198
- if n . Left . Type . Nname ().Func .Inl .Len () != 0 {
199
- * budget -= int ( n . Left . Type . Nname (). Func . InlCost )
202
+ if inlfn := t . Nname ().Func ; inlfn .Inl .Len () != 0 {
203
+ * budget -= inlfn . InlCost
200
204
break
201
205
}
202
206
if Debug ['l' ] < 4 {
0 commit comments