mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: embed type string header in rtype
Reduces binary size of cmd/go by 1%. For #6853. Change-Id: I6f2992a4dd3699db1b532ab08683e82741b9c2e4 Reviewed-on: https://go-review.googlesource.com/19692 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
8dd2ce2b98
commit
a858931200
12 changed files with 61 additions and 59 deletions
|
|
@ -254,7 +254,7 @@ type rtype struct {
|
|||
kind uint8 // enumeration for C
|
||||
alg *typeAlg // algorithm table
|
||||
gcdata *byte // garbage collection data
|
||||
string *string // string form; unnecessary but undeniably useful
|
||||
string string // string form; unnecessary but undeniably useful
|
||||
*uncommonType // (relatively) uncommon fields
|
||||
ptrToThis *rtype // type for pointer to this type, if used in binary or has methods
|
||||
}
|
||||
|
|
@ -460,7 +460,7 @@ func (t *uncommonType) Name() string {
|
|||
return *t.name
|
||||
}
|
||||
|
||||
func (t *rtype) String() string { return *t.string }
|
||||
func (t *rtype) String() string { return t.string }
|
||||
|
||||
func (t *rtype) Size() uintptr { return t.size }
|
||||
|
||||
|
|
@ -1059,7 +1059,7 @@ func (t *rtype) ptrTo() *rtype {
|
|||
}
|
||||
|
||||
// Look in known types.
|
||||
s := "*" + *t.string
|
||||
s := "*" + t.string
|
||||
for _, tt := range typesByString(s) {
|
||||
p = (*ptrType)(unsafe.Pointer(tt))
|
||||
if p.elem == t {
|
||||
|
|
@ -1076,7 +1076,7 @@ func (t *rtype) ptrTo() *rtype {
|
|||
prototype := *(**ptrType)(unsafe.Pointer(&iptr))
|
||||
*p = *prototype
|
||||
|
||||
p.string = &s
|
||||
p.string = s
|
||||
|
||||
// For the type structures linked into the binary, the
|
||||
// compiler provides a good hash of the string.
|
||||
|
|
@ -1328,7 +1328,7 @@ func typesByString(s string) []*rtype {
|
|||
for i < j {
|
||||
h := i + (j-i)/2 // avoid overflow when computing h
|
||||
// i ≤ h < j
|
||||
if !(*typ[h].string >= s) {
|
||||
if !(typ[h].string >= s) {
|
||||
i = h + 1 // preserves f(i-1) == false
|
||||
} else {
|
||||
j = h // preserves f(j) == true
|
||||
|
|
@ -1340,7 +1340,7 @@ func typesByString(s string) []*rtype {
|
|||
// We could do a second binary search, but the caller is going
|
||||
// to do a linear scan anyway.
|
||||
j = i
|
||||
for j < len(typ) && *typ[j].string == s {
|
||||
for j < len(typ) && typ[j].string == s {
|
||||
j++
|
||||
}
|
||||
|
||||
|
|
@ -1442,11 +1442,11 @@ func ChanOf(dir ChanDir, t Type) Type {
|
|||
lookupCache.Unlock()
|
||||
panic("reflect.ChanOf: invalid dir")
|
||||
case SendDir:
|
||||
s = "chan<- " + *typ.string
|
||||
s = "chan<- " + typ.string
|
||||
case RecvDir:
|
||||
s = "<-chan " + *typ.string
|
||||
s = "<-chan " + typ.string
|
||||
case BothDir:
|
||||
s = "chan " + *typ.string
|
||||
s = "chan " + typ.string
|
||||
}
|
||||
for _, tt := range typesByString(s) {
|
||||
ch := (*chanType)(unsafe.Pointer(tt))
|
||||
|
|
@ -1461,7 +1461,7 @@ func ChanOf(dir ChanDir, t Type) Type {
|
|||
ch := new(chanType)
|
||||
*ch = *prototype
|
||||
ch.dir = uintptr(dir)
|
||||
ch.string = &s
|
||||
ch.string = s
|
||||
ch.hash = fnv1(typ.hash, 'c', byte(dir))
|
||||
ch.elem = typ
|
||||
ch.uncommonType = nil
|
||||
|
|
@ -1493,7 +1493,7 @@ func MapOf(key, elem Type) Type {
|
|||
}
|
||||
|
||||
// Look in known types.
|
||||
s := "map[" + *ktyp.string + "]" + *etyp.string
|
||||
s := "map[" + ktyp.string + "]" + etyp.string
|
||||
for _, tt := range typesByString(s) {
|
||||
mt := (*mapType)(unsafe.Pointer(tt))
|
||||
if mt.key == ktyp && mt.elem == etyp {
|
||||
|
|
@ -1505,7 +1505,7 @@ func MapOf(key, elem Type) Type {
|
|||
var imap interface{} = (map[unsafe.Pointer]unsafe.Pointer)(nil)
|
||||
mt := new(mapType)
|
||||
*mt = **(**mapType)(unsafe.Pointer(&imap))
|
||||
mt.string = &s
|
||||
mt.string = s
|
||||
mt.hash = fnv1(etyp.hash, 'm', byte(ktyp.hash>>24), byte(ktyp.hash>>16), byte(ktyp.hash>>8), byte(ktyp.hash))
|
||||
mt.key = ktyp
|
||||
mt.elem = etyp
|
||||
|
|
@ -1605,7 +1605,7 @@ func FuncOf(in, out []Type, variadic bool) Type {
|
|||
}
|
||||
|
||||
// Populate the remaining fields of ft and store in cache.
|
||||
ft.string = &str
|
||||
ft.string = str
|
||||
ft.uncommonType = nil
|
||||
ft.ptrToThis = nil
|
||||
funcLookupCache.m[hash] = append(funcLookupCache.m[hash], &ft.rtype)
|
||||
|
|
@ -1623,9 +1623,9 @@ func funcStr(ft *funcType) string {
|
|||
}
|
||||
if ft.dotdotdot && i == len(ft.in)-1 {
|
||||
repr = append(repr, "..."...)
|
||||
repr = append(repr, *(*sliceType)(unsafe.Pointer(t)).elem.string...)
|
||||
repr = append(repr, (*sliceType)(unsafe.Pointer(t)).elem.string...)
|
||||
} else {
|
||||
repr = append(repr, *t.string...)
|
||||
repr = append(repr, t.string...)
|
||||
}
|
||||
}
|
||||
repr = append(repr, ')')
|
||||
|
|
@ -1638,7 +1638,7 @@ func funcStr(ft *funcType) string {
|
|||
if i > 0 {
|
||||
repr = append(repr, ", "...)
|
||||
}
|
||||
repr = append(repr, *t.string...)
|
||||
repr = append(repr, t.string...)
|
||||
}
|
||||
if len(ft.out) > 1 {
|
||||
repr = append(repr, ')')
|
||||
|
|
@ -1803,8 +1803,8 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
|
|||
b.ptrdata = ptrdata
|
||||
b.kind = kind
|
||||
b.gcdata = gcdata
|
||||
s := "bucket(" + *ktyp.string + "," + *etyp.string + ")"
|
||||
b.string = &s
|
||||
s := "bucket(" + ktyp.string + "," + etyp.string + ")"
|
||||
b.string = s
|
||||
return b
|
||||
}
|
||||
|
||||
|
|
@ -1820,7 +1820,7 @@ func SliceOf(t Type) Type {
|
|||
}
|
||||
|
||||
// Look in known types.
|
||||
s := "[]" + *typ.string
|
||||
s := "[]" + typ.string
|
||||
for _, tt := range typesByString(s) {
|
||||
slice := (*sliceType)(unsafe.Pointer(tt))
|
||||
if slice.elem == typ {
|
||||
|
|
@ -1833,7 +1833,7 @@ func SliceOf(t Type) Type {
|
|||
prototype := *(**sliceType)(unsafe.Pointer(&islice))
|
||||
slice := new(sliceType)
|
||||
*slice = *prototype
|
||||
slice.string = &s
|
||||
slice.string = s
|
||||
slice.hash = fnv1(typ.hash, '[')
|
||||
slice.elem = typ
|
||||
slice.uncommonType = nil
|
||||
|
|
@ -1864,7 +1864,7 @@ func ArrayOf(count int, elem Type) Type {
|
|||
}
|
||||
|
||||
// Look in known types.
|
||||
s := "[" + strconv.Itoa(count) + "]" + *typ.string
|
||||
s := "[" + strconv.Itoa(count) + "]" + typ.string
|
||||
for _, tt := range typesByString(s) {
|
||||
array := (*arrayType)(unsafe.Pointer(tt))
|
||||
if array.elem == typ {
|
||||
|
|
@ -1877,7 +1877,7 @@ func ArrayOf(count int, elem Type) Type {
|
|||
prototype := *(**arrayType)(unsafe.Pointer(&iarray))
|
||||
array := new(arrayType)
|
||||
*array = *prototype
|
||||
array.string = &s
|
||||
array.string = s
|
||||
array.hash = fnv1(typ.hash, '[')
|
||||
for n := uint32(count); n > 0; n >>= 8 {
|
||||
array.hash = fnv1(array.hash, byte(n))
|
||||
|
|
@ -2133,11 +2133,11 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin
|
|||
|
||||
var s string
|
||||
if rcvr != nil {
|
||||
s = "methodargs(" + *rcvr.string + ")(" + *t.string + ")"
|
||||
s = "methodargs(" + rcvr.string + ")(" + t.string + ")"
|
||||
} else {
|
||||
s = "funcargs(" + *t.string + ")"
|
||||
s = "funcargs(" + t.string + ")"
|
||||
}
|
||||
x.string = &s
|
||||
x.string = s
|
||||
|
||||
// cache result for future callers
|
||||
if layoutCache.m == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue