For the OpMap VM instruction, since numElements is known just use the capacity hint. (#347)

This commit is contained in:
Ralph Caraveo III 2021-09-21 05:47:21 -07:00 committed by GitHub
parent de6dc1e9a9
commit d9b300cb70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

2
vm.go
View file

@ -293,7 +293,7 @@ func (v *VM) run() {
case parser.OpMap:
v.ip += 2
numElements := int(v.curInsts[v.ip]) | int(v.curInsts[v.ip-1])<<8
kv := make(map[string]Object)
kv := make(map[string]Object, numElements)
for i := v.sp - numElements; i < v.sp; i += 2 {
key := v.stack[i]
value := v.stack[i+1]