diff --git a/execext/exec.go b/execext/exec.go index b551d2ac..6d1304cc 100644 --- a/execext/exec.go +++ b/execext/exec.go @@ -5,26 +5,11 @@ import ( "errors" "io" "strings" - "sync" "mvdan.cc/sh/interp" "mvdan.cc/sh/syntax" ) -var ( - parserPool = sync.Pool{ - New: func() interface{} { - return syntax.NewParser() - }, - } - - runnerPool = sync.Pool{ - New: func() interface{} { - return &interp.Runner{} - }, - } -) - // RunCommandOptions is the options for the RunCommand func type RunCommandOptions struct { Context context.Context @@ -47,24 +32,19 @@ func RunCommand(opts *RunCommandOptions) error { return ErrNilOptions } - parser := parserPool.Get().(*syntax.Parser) - defer parserPool.Put(parser) - - p, err := parser.Parse(strings.NewReader(opts.Command), "") + p, err := syntax.NewParser().Parse(strings.NewReader(opts.Command), "") if err != nil { return err } - r := runnerPool.Get().(*interp.Runner) - defer runnerPool.Put(r) - - r.Context = opts.Context - r.Dir = opts.Dir - r.Env = opts.Env - r.Stdin = opts.Stdin - r.Stdout = opts.Stdout - r.Stderr = opts.Stderr - + r := interp.Runner{ + Context: opts.Context, + Dir: opts.Dir, + Env: opts.Env, + Stdin: opts.Stdin, + Stdout: opts.Stdout, + Stderr: opts.Stderr, + } if err = r.Reset(); err != nil { return err } diff --git a/execext/exec_test.go b/execext/exec_test.go deleted file mode 100644 index a02cdcb2..00000000 --- a/execext/exec_test.go +++ /dev/null @@ -1,69 +0,0 @@ -// execext_test.go -package execext - -import ( - "context" - "io/ioutil" - "strings" - "sync" - "testing" - - "mvdan.cc/sh/interp" - "mvdan.cc/sh/syntax" -) - -func BenchmarkNoPool(b *testing.B) { - for i := 0; i < b.N; i++ { - f, err := syntax.NewParser().Parse(strings.NewReader(`echo "Hello, World!"`), "") - if err != nil { - panic(err) - } - r := interp.Runner{ - Context: context.TODO(), - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, - } - if err = r.Reset(); err != nil { - panic(err) - } - if err = r.Run(f); err != nil { - panic(err) - } - } -} - -func BenchmarkPool(b *testing.B) { - parserPool := sync.Pool{ - New: func() interface{} { - return syntax.NewParser() - }, - } - runnerPool := sync.Pool{ - New: func() interface{} { - return &interp.Runner{} - }, - } - - for i := 0; i < b.N; i++ { - parser := parserPool.Get().(*syntax.Parser) - defer parserPool.Put(parser) - - f, err := parser.Parse(strings.NewReader(`echo "Hello, World!"`), "") - if err != nil { - panic(err) - } - - r := runnerPool.Get().(*interp.Runner) - defer runnerPool.Put(r) - - r.Stdout = ioutil.Discard - r.Stderr = ioutil.Discard - - if err = r.Reset(); err != nil { - panic(err) - } - if err = r.Run(f); err != nil { - panic(err) - } - } -}