diff options
author | Joe Tsai <joetsai@digital-static.net> | 2022-04-15 18:09:48 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-04-17 00:58:13 +0000 |
commit | e948c3394ee137bae45e85cfa7c8ec0bb0e16dc8 (patch) | |
tree | 192e7c242ca44e90cea223a0f4f49bdd69290d48 | |
parent | 5e4543c29ff930084f79cd982d6eee0f13f52565 (diff) | |
download | go-e948c3394ee137bae45e85cfa7c8ec0bb0e16dc8.tar.gz go-e948c3394ee137bae45e85cfa7c8ec0bb0e16dc8.zip |
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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
-rw-r--r-- | src/reflect/value.go | 13 |
1 files changed, 9 insertions, 4 deletions
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 } |