mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: optimize (reflect.Type).Name
Improves JSON decoding on linux/amd64. name old time/op new time/op delta CodeUnmarshal-40 89.3ms ± 2% 86.3ms ± 2% -3.31% (p=0.000 n=22+22) name old speed new speed delta CodeUnmarshal-40 21.7MB/s ± 2% 22.5MB/s ± 2% +3.44% (p=0.000 n=22+22) Updates #16117 Change-Id: I52acf31d7729400cfe6693e46292d41e1addba3d Reviewed-on: https://go-review.googlesource.com/24410 Run-TryBot: David Crawshaw <crawshaw@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
e369490fb7
commit
e75c899a10
1 changed files with 23 additions and 18 deletions
|
|
@ -891,25 +891,30 @@ func hasPrefix(s, prefix string) bool {
|
||||||
|
|
||||||
func (t *rtype) Name() string {
|
func (t *rtype) Name() string {
|
||||||
s := t.String()
|
s := t.String()
|
||||||
if hasPrefix(s, "map[") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if hasPrefix(s, "struct {") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if hasPrefix(s, "chan ") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if hasPrefix(s, "chan<-") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if hasPrefix(s, "func(") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if hasPrefix(s, "interface {") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
switch s[0] {
|
switch s[0] {
|
||||||
|
case 'm':
|
||||||
|
if hasPrefix(s, "map[") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
case 's':
|
||||||
|
if hasPrefix(s, "struct {") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
case 'c':
|
||||||
|
if hasPrefix(s, "chan ") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if hasPrefix(s, "chan<-") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
case 'f':
|
||||||
|
if hasPrefix(s, "func(") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
case 'i':
|
||||||
|
if hasPrefix(s, "interface {") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
case '[', '*', '<':
|
case '[', '*', '<':
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue