1
0
mirror of https://github.com/golang/go synced 2024-11-19 00:44:40 -07:00

go.tools/go/types: cache method set for pointer-to-named in the Named.

This change improves the complete running time of 'ssadump cmd/oracle' by ~20%.

R=gri, gri
CC=golang-dev
https://golang.org/cl/22910045
This commit is contained in:
Alan Donovan 2013-11-11 17:20:27 -05:00
parent c798b9cca0
commit d8292e2a38

View File

@ -296,11 +296,11 @@ func (c *Chan) Elem() Type { return c.elem }
// A Named represents a named type.
type Named struct {
obj *TypeName // corresponding declared object
underlying Type // possibly a *Named if !complete; never a *Named if complete
complete bool // if set, the underlying type has been determined
methods []*Func // methods declared for this type (not the method set of this type)
mset cachedMethodSet // method set for this type, lazily initialized
obj *TypeName // corresponding declared object
underlying Type // possibly a *Named if !complete; never a *Named if complete
complete bool // if set, the underlying type has been determined
methods []*Func // methods declared for this type (not the method set of this type)
mset, pmset cachedMethodSet // method set for T, *T, lazily initialized
}
// NewNamed returns a new named type for the given type name, underlying type, and associated methods.
@ -341,11 +341,18 @@ func (t *Map) Underlying() Type { return t }
func (t *Chan) Underlying() Type { return t }
func (t *Named) Underlying() Type { return t.underlying }
func (t *Basic) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Array) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Slice) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Struct) MethodSet() *MethodSet { return t.mset.of(t) }
func (t *Pointer) MethodSet() *MethodSet { return t.mset.of(t) }
func (t *Basic) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Array) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Slice) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Struct) MethodSet() *MethodSet { return t.mset.of(t) }
func (t *Pointer) MethodSet() *MethodSet {
if named, _ := t.base.(*Named); named != nil {
// Avoid recomputing mset(*T) for each distinct Pointer
// instance whose underlying type is a named type.
return named.pmset.of(t)
}
return t.mset.of(t)
}
func (t *Tuple) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Signature) MethodSet() *MethodSet { return &emptyMethodSet }
func (t *Builtin) MethodSet() *MethodSet { return &emptyMethodSet }