]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile, etc: use tflag to optimize Name()==""
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 24 Jun 2016 19:28:58 +0000 (15:28 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 24 Jun 2016 20:05:34 +0000 (20:05 +0000)
Improves JSON decoding benchmark:

name                  old time/op    new time/op    delta
CodeDecoder-8           41.3ms ± 6%    39.8ms ± 1%  -3.61%  (p=0.000 n=10+10)

name                  old speed      new speed      delta
CodeDecoder-8         47.0MB/s ± 6%  48.7MB/s ± 1%  +3.66%  (p=0.000 n=10+10)

Change-Id: I524ee05c432fad5252e79b29222ec635c1dee4b4
Reviewed-on: https://go-review.googlesource.com/24452
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/reflect.go
src/reflect/type.go
src/runtime/type.go

index f1a7d3bc8641538136c50734c3114c26981e9d90..cff1acc3436520e8d29dcda134db29a96e5e36c3 100644 (file)
@@ -799,6 +799,7 @@ func typeptrdata(t *Type) int64 {
 const (
        tflagUncommon  = 1 << 0
        tflagExtraStar = 1 << 1
+       tflagNamed     = 1 << 2
 )
 
 var dcommontype_algarray *Sym
@@ -852,6 +853,9 @@ func dcommontype(s *Sym, ot int, t *Type) int {
        if uncommonSize(t) != 0 {
                tflag |= tflagUncommon
        }
+       if t.Sym != nil && t.Sym.Name != "" {
+               tflag |= tflagNamed
+       }
 
        exported := false
        p := Tconv(t, FmtLeft|FmtUnsigned)
index 1c30608cefb692a293e178580da044ec63ebf88f..5b800fc341e777d0922e331553d4507831602885 100644 (file)
@@ -268,6 +268,9 @@ const (
        // a program, the type *T also exists and reusing the str data
        // saves binary size.
        tflagExtraStar tflag = 1 << 1
+
+       // tflagNamed means the type has a name.
+       tflagNamed tflag = 1 << 2
 )
 
 // rtype is the common implementation of most values.
@@ -893,34 +896,10 @@ func hasPrefix(s, prefix string) bool {
 }
 
 func (t *rtype) Name() string {
-       s := t.String()
-       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 '[', '*', '<':
+       if t.tflag&tflagNamed == 0 {
                return ""
        }
+       s := t.String()
        i := len(s) - 1
        for i >= 0 {
                if s[i] == '.' {
index 5ae5c73a226637a8351f53a2845be4943ee633c2..49d3855e4d0abe3b7bf63cf667539356dd3729ae 100644 (file)
@@ -19,6 +19,7 @@ type tflag uint8
 const (
        tflagUncommon  tflag = 1 << 0
        tflagExtraStar tflag = 1 << 1
+       tflagNamed     tflag = 1 << 2
 )
 
 // Needs to be in sync with ../cmd/compile/internal/ld/decodesym.go:/^func.commonsize,
@@ -116,29 +117,10 @@ func hasPrefix(s, prefix string) bool {
 }
 
 func (t *_type) 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 '[', '*', '<':
+       if t.tflag&tflagNamed == 0 {
                return ""
        }
+       s := t.string()
        i := len(s) - 1
        for i >= 0 {
                if s[i] == '.' {