From 3e4e83bf345715f40fc0ec09e4346642ce5548ab Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Fri, 4 Sep 2020 19:33:46 +0900 Subject: [PATCH] Save iter value --- encode_vm.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/encode_vm.go b/encode_vm.go index ca052fc..5f45b04 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -21,6 +21,10 @@ func store(base uintptr, idx uintptr, p uintptr) { *(*uintptr)(unsafe.Pointer(base + idx)) = p } +var ( + globalArray = []interface{}{} +) + func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { recursiveLevel := 0 seenPtr := map[uintptr]struct{}{} @@ -430,6 +434,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { mlen := maplen(unsafe.Pointer(ptr)) if mlen > 0 { iter := mapiterinit(code.typ, unsafe.Pointer(ptr)) + globalArray = append(globalArray, iter) store(ctxptr, code.elemIdx, 0) store(ctxptr, code.length, uintptr(mlen)) store(ctxptr, code.mapIter, uintptr(iter))