]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: optimize (reflect.Type).Name
authorDavid Crawshaw <crawshaw@golang.org>
Thu, 23 Jun 2016 17:32:50 +0000 (13:32 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 23 Jun 2016 18:19:52 +0000 (18:19 +0000)
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>
src/reflect/type.go

index b37fb9f0a55a119789a165a2d1016c1b07e4b293..d60d0b060b278a5d4a317429de81e2fa692749ee 100644 (file)
@@ -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 ""
        }