From 54dd56cbd5c7278f5644e20531f47a1b9c0c4efd Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 5 May 2017 16:22:11 +0100 Subject: [PATCH] Use cork encoder/decoder pools --- util/pack/pack.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/util/pack/pack.go b/util/pack/pack.go index 73e4108a..9364a52d 100644 --- a/util/pack/pack.go +++ b/util/pack/pack.go @@ -19,24 +19,26 @@ import ( "github.com/abcum/cork" ) -var opt cork.Handle - -func init() { - opt.Precision = false - opt.ArrType = []interface{}{} - opt.MapType = map[string]interface{}{} +var opt = cork.Handle{ + Precision: false, + ArrType: make([]interface{}, 0), + MapType: make(map[string]interface{}), } // Encode encodes a data object into a CORK. func Encode(src interface{}) (dst []byte) { buf := bytes.NewBuffer(nil) - cork.NewEncoder(buf).Options(&opt).Encode(src) + enc := cork.NewEncoderFromPool(buf).Options(&opt) + enc.Encode(src) + enc.Done() return buf.Bytes() } // Decode decodes a CORK into a data object. func Decode(src []byte, dst interface{}) { buf := bytes.NewReader(src) - cork.NewDecoder(buf).Options(&opt).Decode(dst) + dec := cork.NewDecoderFromPool(buf).Options(&opt) + dec.Decode(dst) + dec.Done() return }