File tree 3 files changed +172
-71
lines changed
3 files changed +172
-71
lines changed Original file line number Diff line number Diff line change @@ -3988,8 +3988,8 @@ func TestValuePanic(t *testing.T) {
3988
3988
shouldPanic ("reflect.Value.Addr of unaddressable value" , func () { vo (0 ).Addr () })
3989
3989
shouldPanic ("call of reflect.Value.Bool on float64 Value" , func () { vo (0.0 ).Bool () })
3990
3990
shouldPanic ("call of reflect.Value.Bytes on string Value" , func () { vo ("" ).Bytes () })
3991
- shouldPanic ("call of reflect.Value.Call on bool Value" , func () { vo (true ).Call (nil ) })
3992
- shouldPanic ("call of reflect.Value.CallSlice on int Value" , func () { vo (0 ).CallSlice (nil ) })
3991
+ shouldPanic ("call of reflect.Value.Caller on bool Value" , func () { vo (true ).Call (nil ) })
3992
+ shouldPanic ("call of reflect.Value.Caller on int Value" , func () { vo (0 ).CallSlice (nil ) })
3993
3993
shouldPanic ("call of reflect.Value.Close on string Value" , func () { vo ("" ).Close () })
3994
3994
shouldPanic ("call of reflect.Value.Complex on float64 Value" , func () { vo (0.0 ).Complex () })
3995
3995
shouldPanic ("call of reflect.Value.Elem on bool Value" , func () { vo (false ).Elem () })
@@ -8408,3 +8408,19 @@ func TestClear(t *testing.T) {
8408
8408
})
8409
8409
}
8410
8410
}
8411
+
8412
+ func TestCaller_CallReusesOutValues (t * testing.T ) {
8413
+ fn := func () int {
8414
+ return 27
8415
+ }
8416
+
8417
+ var i int
8418
+ v := ValueOf (& i ).Elem ()
8419
+ out := []Value {v }
8420
+
8421
+ ValueOf (fn ).Caller ().Call ([]Value {}, out )
8422
+
8423
+ if i != 27 {
8424
+ t .Errorf ("unexpected result for output value; got %d, want 27" , i )
8425
+ }
8426
+ }
Original file line number Diff line number Diff line change @@ -197,6 +197,19 @@ func BenchmarkCall(b *testing.B) {
197
197
})
198
198
}
199
199
200
+ func BenchmarkCallerCall (b * testing.B ) {
201
+ fv := ValueOf (func (a , b string ) {})
202
+ c := fv .Caller ()
203
+ out := make ([]Value , c .Type ().NumOut ())
204
+ b .ReportAllocs ()
205
+ b .RunParallel (func (pb * testing.PB ) {
206
+ args := []Value {ValueOf ("a" ), ValueOf ("b" )}
207
+ for pb .Next () {
208
+ c .Call (args , out )
209
+ }
210
+ })
211
+ }
212
+
200
213
type myint int64
201
214
202
215
func (i * myint ) inc () {
@@ -213,6 +226,17 @@ func BenchmarkCallMethod(b *testing.B) {
213
226
}
214
227
}
215
228
229
+ func BenchmarkCallerCallMethod (b * testing.B ) {
230
+ b .ReportAllocs ()
231
+ z := new (myint )
232
+
233
+ v := ValueOf (z .inc )
234
+ c := v .Caller ()
235
+ for i := 0 ; i < b .N ; i ++ {
236
+ c .Call (nil , nil )
237
+ }
238
+ }
239
+
216
240
func BenchmarkCallArgCopy (b * testing.B ) {
217
241
byteArray := func (n int ) Value {
218
242
return Zero (ArrayOf (n , TypeOf (byte (0 ))))
You can’t perform that action at this time.
0 commit comments