mirror of
https://github.com/go-task/task.git
synced 2025-01-06 03:53:54 +02:00
Revert "execext: use sync.Pool to instantiate parser and runner"
This reverts commit 451b965fb0
.
This commit is contained in:
parent
7a64530e83
commit
5e72de4ba2
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user