Compare commits

...

1 Commits

Author SHA1 Message Date
Masaaki Goshima 397b667f34 Improve decoder's memory footprint 2021-04-10 15:30:46 +09:00
1 changed files with 2 additions and 4 deletions

View File

@ -28,8 +28,7 @@ const (
) )
func unmarshal(data []byte, v interface{}) error { func unmarshal(data []byte, v interface{}) error {
src := make([]byte, len(data)+1) // append nul byte to the end src := append(data, nul) // append nul byte to the end
copy(src, data)
header := (*emptyInterface)(unsafe.Pointer(&v)) header := (*emptyInterface)(unsafe.Pointer(&v))
@ -47,8 +46,7 @@ func unmarshal(data []byte, v interface{}) error {
} }
func unmarshalNoEscape(data []byte, v interface{}) error { func unmarshalNoEscape(data []byte, v interface{}) error {
src := make([]byte, len(data)+1) // append nul byte to the end src := append(data, nul) // append nul byte to the end
copy(src, data)
header := (*emptyInterface)(unsafe.Pointer(&v)) header := (*emptyInterface)(unsafe.Pointer(&v))