Improve decoder's memory footprint

This commit is contained in:
Masaaki Goshima 2021-04-10 15:30:46 +09:00
parent a39bc30ed9
commit 397b667f34
1 changed files with 2 additions and 4 deletions

View File

@ -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))