expr icon indicating copy to clipboard operation
expr copied to clipboard

Remove reflect from FastCall path

Open antonmedv opened this issue 3 years ago • 0 comments
trafficstars

Even if a function is defined in a fetcher, expr still used FetchFn and uses reflection unlike pure variables in a struct. FetchFn is guaranteed to use reflection.

func FetchFn(from interface{}, name string) reflect.Value {
	v := reflect.ValueOf(from)

	// Methods can be defined on any type.
	if v.NumMethod() > 0 {
		method := v.MethodByName(name)  //MethodByName utilizes reflection. Can this be avoided all together?
		if method.IsValid() {
			return method
		}
	}

Thank you.

Originally posted by @gitperson1980 in https://github.com/antonmedv/expr/issues/217#issuecomment-1011276835

antonmedv avatar Jun 21 '22 08:06 antonmedv