aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/type.go
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2016-04-07 16:29:16 -0400
committerDavid Crawshaw <crawshaw@golang.org>2016-04-22 10:08:05 +0000
commit1492e7db059ea7903110b0725d5ced3134558e73 (patch)
tree55b92fbd4305828b28b431a2d05f0291ca932af1 /src/runtime/type.go
parentbb52ceafea60dc4688b6c6b71f241752ce597db8 (diff)
downloadgo-1492e7db059ea7903110b0725d5ced3134558e73.tar.xz
cmd/compile, etc: use nameOff for rtype string
linux/amd64: cmd/go: -8KB (basically nothing) linux/amd64 PIE: cmd/go: -191KB (1.6%) jujud: -1.5MB (1.9%) Updates #6853 Fixes #15064 Change-Id: I0adbb95685e28be92e8548741df0e11daa0a9b5f Reviewed-on: https://go-review.googlesource.com/21777 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/type.go')
-rw-r--r--src/runtime/type.go46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/runtime/type.go b/src/runtime/type.go
index 31f7ff81b8..0b28fa6d43 100644
--- a/src/runtime/type.go
+++ b/src/runtime/type.go
@@ -8,10 +8,18 @@ package runtime
import "unsafe"
-// tflag is documented in ../reflect/type.go.
+// tflag is documented in reflect/type.go.
+//
+// tflag values must be kept in sync with copies in:
+// cmd/compile/internal/gc/reflect.go
+// cmd/link/internal/ld/decodesym.go
+// reflect/type.go
type tflag uint8
-const tflagUncommon tflag = 1
+const (
+ tflagUncommon tflag = 1 << 0
+ tflagExtraStar tflag = 1 << 1
+)
// Needs to be in sync with ../cmd/compile/internal/ld/decodesym.go:/^func.commonsize,
// ../cmd/compile/internal/gc/reflect.go:/^func.dcommontype and
@@ -28,8 +36,17 @@ type _type struct {
// gcdata stores the GC type data for the garbage collector.
// If the KindGCProg bit is set in kind, gcdata is a GC program.
// Otherwise it is a ptrmask bitmap. See mbitmap.go for details.
- gcdata *byte
- _string string
+ gcdata *byte
+ str nameOff
+ _ int32
+}
+
+func (t *_type) string() string {
+ s := t.nameOff(t.str).name()
+ if t.tflag&tflagExtraStar != 0 {
+ return s[1:]
+ }
+ return s
}
func (t *_type) uncommon() *uncommontype {
@@ -99,33 +116,34 @@ func hasPrefix(s, prefix string) bool {
}
func (t *_type) name() string {
- if hasPrefix(t._string, "map[") {
+ s := t.string()
+ if hasPrefix(s, "map[") {
return ""
}
- if hasPrefix(t._string, "struct {") {
+ if hasPrefix(s, "struct {") {
return ""
}
- if hasPrefix(t._string, "chan ") {
+ if hasPrefix(s, "chan ") {
return ""
}
- if hasPrefix(t._string, "chan<-") {
+ if hasPrefix(s, "chan<-") {
return ""
}
- if hasPrefix(t._string, "func(") {
+ if hasPrefix(s, "func(") {
return ""
}
- switch t._string[0] {
+ switch s[0] {
case '[', '*', '<':
return ""
}
- i := len(t._string) - 1
+ i := len(s) - 1
for i >= 0 {
- if t._string[i] == '.' {
+ if s[i] == '.' {
break
}
i--
}
- return t._string[i+1:]
+ return s[i+1:]
}
// reflectOffs holds type offsets defined at run time by the reflect package.
@@ -497,7 +515,7 @@ func typesEqual(t, v *_type) bool {
if kind != v.kind&kindMask {
return false
}
- if t._string != v._string {
+ if t.string() != v.string() {
return false
}
ut := t.uncommon()