Skip to content

Commit

Permalink
reduce alloc in unsafe API
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispqt committed May 1, 2018
1 parent c5402e6 commit a3885ea
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions decode_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a3885ea

Please sign in to comment.