Commit e75c899a authored by David Crawshaw's avatar David Crawshaw

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: default avatarIan Lance Taylor <iant@golang.org>
parent e369490f
......@@ -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 ""
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment