Skip to content

Commit 9733e9a

Browse files
author
kelindar
committed
rollback pool, no reset
1 parent 73c8fa4 commit 9733e9a

1 file changed

Lines changed: 1 addition & 51 deletions

File tree

script.go

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,12 @@ type vm struct {
146146
argn int // The number of arguments
147147
exec *lua.LState // The pool of runtimes for concurrent use
148148
main *lua.LFunction // The main function
149-
tbls *tablePool // Pool of tables
150149
}
151150

152151
// newVM creates a new VM for a script
153152
func newVM(s *Script) (*vm, error) {
154153
l := newState()
155154
v := &vm{
156-
tbls: newTablePool(l),
157155
exec: l,
158156
argn: 0,
159157
main: nil,
@@ -192,20 +190,7 @@ func (v *vm) Run(ctx context.Context, args []any) (Value, error) {
192190
exec.SetContext(ctx)
193191
exec.Push(v.main)
194192
for _, arg := range args {
195-
switch x := arg.(type) {
196-
case Table:
197-
defer pushArg(x, exec, v.tbls)()
198-
case Bools:
199-
defer pushArg(x, exec, v.tbls)()
200-
case Strings:
201-
defer pushArg(x, exec, v.tbls)()
202-
case Numbers:
203-
defer pushArg(x, exec, v.tbls)()
204-
case Array:
205-
defer pushArg(x, exec, v.tbls)()
206-
default:
207-
exec.Push(lvalueOf(exec, arg))
208-
}
193+
exec.Push(lvalueOf(exec, arg))
209194
}
210195

211196
// Call the main function
@@ -232,41 +217,6 @@ func newState() *lua.LState {
232217

233218
// --------------------------------------------------------------------
234219

235-
type tablePool struct {
236-
sync.Pool
237-
}
238-
239-
// newTablePool creates a new table pool
240-
func newTablePool(state *lua.LState) *tablePool {
241-
return &tablePool{
242-
Pool: sync.Pool{
243-
New: func() any { return state.NewTable() },
244-
},
245-
}
246-
}
247-
248-
// Get gets a table from the pool
249-
func (b *tablePool) Get() *lua.LTable {
250-
return b.Pool.Get().(*lua.LTable)
251-
}
252-
253-
// Put puts a table back into the pool
254-
func (b *tablePool) Put(x *lua.LTable) {
255-
b.Pool.Put(x)
256-
}
257-
258-
// pushArg pushes an argument into the state
259-
func pushArg[T tableType](value T, state *lua.LState, p *tablePool) func() {
260-
dst := p.Get()
261-
value.lcopy(dst, state)
262-
state.Push(dst)
263-
return func() {
264-
p.Put(dst)
265-
}
266-
}
267-
268-
// --------------------------------------------------------------------
269-
270220
// defaultConcurrency sets the default concurrency for the VM pool
271221
var defaultConcurrency = int(math.Min(
272222
float64(runtime.GOMAXPROCS(-1)), float64(runtime.NumCPU()),

0 commit comments

Comments
 (0)