From 397b667f34ca15d46b781ca619af296427375335 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 10 Apr 2021 15:30:46 +0900 Subject: [PATCH] Improve decoder's memory footprint --- decode.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/decode.go b/decode.go index d06136d..641e22c 100644 --- a/decode.go +++ b/decode.go @@ -28,8 +28,7 @@ const ( ) func unmarshal(data []byte, v interface{}) error { - src := make([]byte, len(data)+1) // append nul byte to the end - copy(src, data) + src := append(data, nul) // append nul byte to the end header := (*emptyInterface)(unsafe.Pointer(&v)) @@ -47,8 +46,7 @@ func unmarshal(data []byte, v interface{}) error { } func unmarshalNoEscape(data []byte, v interface{}) error { - src := make([]byte, len(data)+1) // append nul byte to the end - copy(src, data) + src := append(data, nul) // append nul byte to the end header := (*emptyInterface)(unsafe.Pointer(&v))