From 18a6e4cffe09fc4ef9c5b2c8fda8a430159fb641 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Tue, 1 Sep 2020 22:39:20 +0900 Subject: [PATCH] Remove codePool --- encode.go | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/encode.go b/encode.go index 4ca7216..6297a1a 100644 --- a/encode.go +++ b/encode.go @@ -36,8 +36,8 @@ type opcodeMap struct { } type opcodeSet struct { - codeIndent sync.Pool - code sync.Pool + codeIndent *opcode + code *opcode ctx sync.Pool } @@ -158,20 +158,15 @@ func (e *Encoder) encode(v interface{}) error { if codeSet := cachedOpcode.get(typeptr); codeSet != nil { var code *opcode if e.enabledIndent { - code = codeSet.codeIndent.Get().(*opcode) + code = codeSet.codeIndent } else { - code = codeSet.code.Get().(*opcode) + code = codeSet.code } ctx := codeSet.ctx.Get().(*encodeRuntimeContext) p := uintptr(header.ptr) ctx.init(p) seenPtr := map[uintptr]struct{}{} err := e.run(ctx, 0, seenPtr, code) - if e.enabledIndent { - codeSet.codeIndent.Put(code) - } else { - codeSet.code.Put(code) - } codeSet.ctx.Put(ctx) return err } @@ -197,16 +192,8 @@ func (e *Encoder) encode(v interface{}) error { } codeLength := code.totalLength() codeSet := &opcodeSet{ - codeIndent: sync.Pool{ - New: func() interface{} { - return codeIndent - }, - }, - code: sync.Pool{ - New: func() interface{} { - return code - }, - }, + codeIndent: codeIndent, + code: code, ctx: sync.Pool{ New: func() interface{} { return &encodeRuntimeContext{