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
1 changed files with 17 additions and 10 deletions

View File

@ -300,7 +300,7 @@ type Named struct {
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
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.
@ -345,7 +345,14 @@ 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 *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 }