From: Joe Tsai Date: Sat, 16 Apr 2022 01:09:48 +0000 (-0700) Subject: reflect: make Value.Type inlineable X-Git-Tag: go1.19beta1~648 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e948c3394ee137bae45e85cfa7c8ec0bb0e16dc8;p=gostls13.git reflect: make Value.Type inlineable This allows the result of Type to be computed much faster. Performance: old new delta 1.76ns 0.66ns -62.27% Change-Id: Ie007fd175aaa41b2f67c71fa2a34ab8d292dd0e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/400335 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: Daniel Martí Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- diff --git a/src/reflect/value.go b/src/reflect/value.go index 2496cbe463..06f0469ede 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -2465,12 +2465,17 @@ func (v Value) TrySend(x Value) bool { // Type returns v's type. func (v Value) Type() Type { - f := v.flag - if f == 0 { + if v.flag != 0 && v.flag&flagMethod == 0 { + return v.typ + } + return v.typeSlow() +} + +func (v Value) typeSlow() Type { + if v.flag == 0 { panic(&ValueError{"reflect.Value.Type", Invalid}) } - if f&flagMethod == 0 { - // Easy case + if v.flag&flagMethod == 0 { return v.typ }