diff --git a/encode.go b/encode.go index 6297a1a..f139c5c 100644 --- a/encode.go +++ b/encode.go @@ -165,8 +165,7 @@ func (e *Encoder) encode(v interface{}) error { ctx := codeSet.ctx.Get().(*encodeRuntimeContext) p := uintptr(header.ptr) ctx.init(p) - seenPtr := map[uintptr]struct{}{} - err := e.run(ctx, 0, seenPtr, code) + err := e.run(ctx, code) codeSet.ctx.Put(ctx) return err } @@ -214,8 +213,7 @@ func (e *Encoder) encode(v interface{}) error { c = code } - seenPtr := map[uintptr]struct{}{} - if err := e.run(ctx, 0, seenPtr, c); err != nil { + if err := e.run(ctx, c); err != nil { codeSet.ctx.Put(ctx) return err } diff --git a/encode_vm.go b/encode_vm.go index 813ef8b..ca052fc 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -21,9 +21,12 @@ func store(base uintptr, idx uintptr, p uintptr) { *(*uintptr)(unsafe.Pointer(base + idx)) = p } -func (e *Encoder) run(ctx *encodeRuntimeContext, recursiveLevel int, seenPtr map[uintptr]struct{}, code *opcode) error { +func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { + recursiveLevel := 0 + seenPtr := map[uintptr]struct{}{} ptrOffset := uintptr(0) ctxptr := ctx.ptr() + for { switch code.op { case opPtr: