mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +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
|
@ -891,25 +891,30 @@ func hasPrefix(s, prefix string) bool {
|
|||
|
||||
func (t *rtype) Name() 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] {
|
||||
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 '[', '*', '<':
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue