go: Use unsafe.Slice()

This commit is contained in:
Abi Hafshin Alfarouq 2021-12-08 15:01:23 +07:00 committed by GitHub
parent 4ec67035c0
commit 6f50e75cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,11 +106,7 @@ func (w *Writer) writeChunk(p []byte, op C.BrotliEncoderOperation) (n int, err e
length := int(result.output_data_size)
if length != 0 {
// It is a workaround for non-copying-wrapping of native memory.
// C-encoder never pushes output block longer than ((2 << 25) + 502).
// TODO(eustas): use natural wrapper, when it becomes available, see
// https://golang.org/issue/13656.
output := (*[1 << 30]byte)(unsafe.Pointer(result.output_data))[:length:length]
output := unsafe.Slice((*byte)(unsafe.Pointer(result.output_data)), length)
_, err = w.dst.Write(output)
if err != nil {
return n, err