Reset seenPtr

This commit is contained in:
Masaaki Goshima 2020-08-31 00:14:32 +09:00
parent 70f8f01ef3
commit 572d4842a5
2 changed files with 6 additions and 0 deletions

View File

@ -164,6 +164,7 @@ func (e *Encoder) encode(v interface{}) error {
}
ctx := codeSet.ctx.Get().(*encodeRuntimeContext)
p := uintptr(header.ptr)
ctx.reset()
ctx.init(p)
err := e.run(ctx, code)
if e.enabledIndent {
@ -218,6 +219,7 @@ func (e *Encoder) encode(v interface{}) error {
cachedOpcode.set(typeptr, codeSet)
p := uintptr(header.ptr)
ctx := codeSet.ctx.Get().(*encodeRuntimeContext)
ctx.reset()
ctx.init(p)
if e.enabledIndent {
err := e.run(ctx, codeIndent)

View File

@ -63,6 +63,10 @@ type encodeRuntimeContext struct {
seenPtr map[uintptr]struct{}
}
func (c *encodeRuntimeContext) reset() {
c.seenPtr = map[uintptr]struct{}{}
}
func (c *encodeRuntimeContext) init(p uintptr) {
c.ptrs[0] = p
}