mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 11:36:56 +08:00
change: cache loaded functions to improve performance
This commit is contained in:
@@ -18,7 +18,8 @@ func newParser() *parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type parser struct {
|
type parser struct {
|
||||||
plugin hrpPlugin // plugin is used to call functions
|
plugin hrpPlugin // plugin is used to call functions
|
||||||
|
cachedFunctions map[string]reflect.Value // cache loaded functions to improve performance
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildURL(baseURL, stepURL string) string {
|
func buildURL(baseURL, stepURL string) string {
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ func (p *goPlugin) quit() error {
|
|||||||
|
|
||||||
// hashicorpPlugin implements hashicorp/go-plugin
|
// hashicorpPlugin implements hashicorp/go-plugin
|
||||||
type hashicorpPlugin struct {
|
type hashicorpPlugin struct {
|
||||||
cachedFunctions map[string]reflect.Value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *hashicorpPlugin) init(path string) error {
|
func (p *hashicorpPlugin) init(path string) error {
|
||||||
@@ -178,12 +177,17 @@ func locatePlugin(startPath string, destPluginFile pluginFile) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) getMappingFunction(funcName string) (reflect.Value, error) {
|
func (p *parser) getMappingFunction(funcName string) (reflect.Value, error) {
|
||||||
|
if function, ok := p.cachedFunctions[funcName]; ok {
|
||||||
|
return function, nil
|
||||||
|
}
|
||||||
|
|
||||||
var fn reflect.Value
|
var fn reflect.Value
|
||||||
|
|
||||||
// get function from plugin
|
// get function from plugin
|
||||||
if p.plugin != nil {
|
if p.plugin != nil {
|
||||||
fn, err := p.plugin.lookup(funcName)
|
fn, err := p.plugin.lookup(funcName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
p.cachedFunctions[funcName] = fn
|
||||||
return fn, nil
|
return fn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,6 +195,7 @@ func (p *parser) getMappingFunction(funcName string) (reflect.Value, error) {
|
|||||||
// get builtin function
|
// get builtin function
|
||||||
if function, ok := builtin.Functions[funcName]; ok {
|
if function, ok := builtin.Functions[funcName]; ok {
|
||||||
fn = reflect.ValueOf(function)
|
fn = reflect.ValueOf(function)
|
||||||
|
p.cachedFunctions[funcName] = fn
|
||||||
return fn, nil
|
return fn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user