From a3885eabb90cc233617149549ee16c62b884144b Mon Sep 17 00:00:00 2001 From: francoispqt Date: Tue, 1 May 2018 21:53:03 +0800 Subject: [PATCH] reduce alloc in unsafe API --- decode_unsafe.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/decode_unsafe.go b/decode_unsafe.go index 6cc18ec..0720356 100644 --- a/decode_unsafe.go +++ b/decode_unsafe.go @@ -14,7 +14,7 @@ var Unsafe = decUnsafe{} type decUnsafe struct{} func (u decUnsafe) UnmarshalArray(data []byte, v UnmarshalerArray) error { - dec := BorrowDecoder(nil) + dec := borrowDecoder(nil, 0) defer dec.Release() dec.data = data dec.length = len(data) @@ -29,7 +29,7 @@ func (u decUnsafe) UnmarshalArray(data []byte, v UnmarshalerArray) error { } func (u decUnsafe) UnmarshalObject(data []byte, v UnmarshalerObject) error { - dec := BorrowDecoder(nil) + dec := borrowDecoder(nil, 0) defer dec.Release() dec.data = data dec.length = len(data) @@ -48,52 +48,52 @@ func (u decUnsafe) Unmarshal(data []byte, v interface{}) error { var dec *Decoder switch vt := v.(type) { case *string: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeString(vt) case *int: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeInt(vt) case *int32: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeInt32(vt) case *uint32: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeUint32(vt) case *int64: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeInt64(vt) case *uint64: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeUint64(vt) case *float64: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeFloat64(vt) case *bool: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data err = dec.decodeBool(vt) case UnmarshalerObject: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data _, err = dec.decodeObject(vt) case UnmarshalerArray: - dec = BorrowDecoder(nil) + dec = borrowDecoder(nil, 0) dec.length = len(data) dec.data = data _, err = dec.decodeArray(vt)