1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-04-27 12:32:45 +02:00

add pointer receiver into all Functions methods

This commit is contained in:
3timeslazy 2019-10-15 12:04:04 +03:00
parent 83dc0d2811
commit 1a7240f738
3 changed files with 11 additions and 11 deletions

View File

@ -14,7 +14,7 @@ const emptyNS = ""
const separator = "::"
type NamespaceContainer struct {
funcs core.Functions
funcs *core.Functions
name string
}
@ -25,7 +25,7 @@ func newRootNamespace() *NamespaceContainer {
return ns
}
func newNamespace(funcs core.Functions, name string) *NamespaceContainer {
func newNamespace(funcs *core.Functions, name string) *NamespaceContainer {
return &NamespaceContainer{funcs, strings.ToUpper(name)}
}

View File

@ -24,11 +24,11 @@ type (
visitor struct {
*fql.BaseFqlParserVisitor
src string
funcs core.Functions
funcs *core.Functions
}
)
func newVisitor(src string, funcs core.Functions) *visitor {
func newVisitor(src string, funcs *core.Functions) *visitor {
return &visitor{
&fql.BaseFqlParserVisitor{},
src,

View File

@ -48,38 +48,38 @@ type (
)
// NewFunctions returns new empty Functions.
func NewFunctions() Functions {
return Functions{
func NewFunctions() *Functions {
return &Functions{
functions: make(FunctionsMap),
}
}
// Get returns the function with the given name. If the function
// does not exist it returns nil, false.
func (fns Functions) Get(name string) (Function, bool) {
func (fns *Functions) Get(name string) (Function, bool) {
fn, exists := fns.functions[strings.ToUpper(name)]
return fn, exists
}
// Set sets the function with the given name. If the function
// with the such name already exists it will be overwritten.
func (fns Functions) Set(name string, fn Function) {
func (fns *Functions) Set(name string, fn Function) {
// the preferred way to create Functions is NewFunctions.
// But just in case, if someone creates differently
if fns.functions == nil {
fns.functions = make(FunctionsMap)
fns.functions = make(FunctionsMap, 1)
}
fns.functions[strings.ToUpper(name)] = fn
}
// Unset delete the function with the given name.
func (fns Functions) Unset(name string) {
func (fns *Functions) Unset(name string) {
delete(fns.functions, strings.ToUpper(name))
}
// Names returns the names of the internal functions.
func (fns Functions) Names() []string {
func (fns *Functions) Names() []string {
names := make([]string, 0, len(fns.functions))
for name := range fns.functions {