1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-07-03 00:46:51 +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 = "::" const separator = "::"
type NamespaceContainer struct { type NamespaceContainer struct {
funcs core.Functions funcs *core.Functions
name string name string
} }
@ -25,7 +25,7 @@ func newRootNamespace() *NamespaceContainer {
return ns return ns
} }
func newNamespace(funcs core.Functions, name string) *NamespaceContainer { func newNamespace(funcs *core.Functions, name string) *NamespaceContainer {
return &NamespaceContainer{funcs, strings.ToUpper(name)} return &NamespaceContainer{funcs, strings.ToUpper(name)}
} }

View File

@ -24,11 +24,11 @@ type (
visitor struct { visitor struct {
*fql.BaseFqlParserVisitor *fql.BaseFqlParserVisitor
src string 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{ return &visitor{
&fql.BaseFqlParserVisitor{}, &fql.BaseFqlParserVisitor{},
src, src,

View File

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