Source File
methodlist.go
Belonging Package
go/types
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types
import
// methodList holds a list of methods that may be lazily resolved by a provided
// resolution method.
type methodList struct {
methods []*Func
// guards synchronizes the instantiation of lazy methods. For lazy method
// lists, guards is non-nil and of the length passed to newLazyMethodList.
// For non-lazy method lists, guards is nil.
guards *[]sync.Once
}
// newMethodList creates a non-lazy method list holding the given methods.
func ( []*Func) *methodList {
return &methodList{methods: }
}
// newLazyMethodList creates a lazy method list of the given length. Methods
// may be resolved lazily for a given index by providing a resolver function.
func ( int) *methodList {
:= make([]sync.Once, )
return &methodList{
methods: make([]*Func, ),
guards: &,
}
}
// isLazy reports whether the receiver is a lazy method list.
func ( *methodList) () bool {
return != nil && .guards != nil
}
// Add appends a method to the method list if not not already present. Add
// panics if the receiver is lazy.
func ( *methodList) ( *Func) {
assert(!.isLazy())
if , := lookupMethod(.methods, .pkg, .name, false); < 0 {
.methods = append(.methods, )
}
}
// Lookup looks up the method identified by pkg and name in the receiver.
// Lookup panics if the receiver is lazy. If foldCase is true, method names
// are considered equal if they are equal with case folding.
func ( *methodList) ( *Package, string, bool) (int, *Func) {
assert(!.isLazy())
if == nil {
return -1, nil
}
return lookupMethod(.methods, , , )
}
// Len returns the length of the method list.
func ( *methodList) () int {
if == nil {
return 0
}
return len(.methods)
}
// At returns the i'th method of the method list. At panics if i is out of
// bounds, or if the receiver is lazy and resolve is nil.
func ( *methodList) ( int, func() *Func) *Func {
if !.isLazy() {
return .methods[]
}
assert( != nil)
(*.guards)[].Do(func() {
.methods[] = ()
})
return .methods[]
}
The pages are generated with Golds v0.4.9. (GOOS=linux GOARCH=amd64)