vm: microoptimize new estack creation

Subslice won't reach element -1, but it can reuse the same buffer space more
effectively.
This commit is contained in:
Roman Khimov 2022-05-31 18:53:05 +03:00
parent 10110d4e70
commit 3d4076ca36
2 changed files with 9 additions and 1 deletions

View file

@ -132,6 +132,14 @@ func newStack(n string, refc *refCounter) *Stack {
initStack(s, n, refc)
return s
}
func subStack(old *Stack) *Stack {
s := new(Stack)
*s = *old
s.elems = s.elems[len(s.elems):]
return s
}
func initStack(s *Stack, n string, refc *refCounter) {
s.name = n
s.refs = refc