Remove codePool

This commit is contained in:
Masaaki Goshima 2020-09-01 22:39:20 +09:00
parent 3aa921e884
commit 18a6e4cffe
1 changed files with 6 additions and 19 deletions

View File

@ -36,8 +36,8 @@ type opcodeMap struct {
} }
type opcodeSet struct { type opcodeSet struct {
codeIndent sync.Pool codeIndent *opcode
code sync.Pool code *opcode
ctx sync.Pool ctx sync.Pool
} }
@ -158,20 +158,15 @@ func (e *Encoder) encode(v interface{}) error {
if codeSet := cachedOpcode.get(typeptr); codeSet != nil { if codeSet := cachedOpcode.get(typeptr); codeSet != nil {
var code *opcode var code *opcode
if e.enabledIndent { if e.enabledIndent {
code = codeSet.codeIndent.Get().(*opcode) code = codeSet.codeIndent
} else { } else {
code = codeSet.code.Get().(*opcode) code = codeSet.code
} }
ctx := codeSet.ctx.Get().(*encodeRuntimeContext) ctx := codeSet.ctx.Get().(*encodeRuntimeContext)
p := uintptr(header.ptr) p := uintptr(header.ptr)
ctx.init(p) ctx.init(p)
seenPtr := map[uintptr]struct{}{} seenPtr := map[uintptr]struct{}{}
err := e.run(ctx, 0, seenPtr, code) err := e.run(ctx, 0, seenPtr, code)
if e.enabledIndent {
codeSet.codeIndent.Put(code)
} else {
codeSet.code.Put(code)
}
codeSet.ctx.Put(ctx) codeSet.ctx.Put(ctx)
return err return err
} }
@ -197,16 +192,8 @@ func (e *Encoder) encode(v interface{}) error {
} }
codeLength := code.totalLength() codeLength := code.totalLength()
codeSet := &opcodeSet{ codeSet := &opcodeSet{
codeIndent: sync.Pool{ codeIndent: codeIndent,
New: func() interface{} { code: code,
return codeIndent
},
},
code: sync.Pool{
New: func() interface{} {
return code
},
},
ctx: sync.Pool{ ctx: sync.Pool{
New: func() interface{} { New: func() interface{} {
return &encodeRuntimeContext{ return &encodeRuntimeContext{