From f051ec64639b83faabcfe766ff078072def3c2aa Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Wed, 17 Feb 2021 17:39:24 -0800 Subject: Add gohacks.Slice/StringHeader. See https://github.com/golang/go/issues/19367 for rationale. Note that the upstream decision arrived at in that thread, while useful for some of our use cases, doesn't account for all of our SliceHeader use cases (we often use SliceHeader to extract pointers from slices in a way that avoids bounds checking and/or handles nil slices correctly) and also doesn't exist yet. PiperOrigin-RevId: 358071574 --- pkg/flipcall/flipcall_unsafe.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'pkg/flipcall/flipcall_unsafe.go') diff --git a/pkg/flipcall/flipcall_unsafe.go b/pkg/flipcall/flipcall_unsafe.go index 580bf23a4..613ed8943 100644 --- a/pkg/flipcall/flipcall_unsafe.go +++ b/pkg/flipcall/flipcall_unsafe.go @@ -61,13 +61,12 @@ func (ep *Endpoint) dataLen() *uint32 { // - Writers must not assume that they will read back the same data that they // have written. In other words, writers should avoid reading from Data() at // all. -func (ep *Endpoint) Data() []byte { - var bs []byte - bsReflect := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) - bsReflect.Data = ep.packet + PacketHeaderBytes - bsReflect.Len = int(ep.dataCap) - bsReflect.Cap = int(ep.dataCap) - return bs +func (ep *Endpoint) Data() (bs []byte) { + bshdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) + bshdr.Data = ep.packet + PacketHeaderBytes + bshdr.Len = int(ep.dataCap) + bshdr.Cap = int(ep.dataCap) + return } // ioSync is a dummy variable used to indicate synchronization to the Go race -- cgit v1.2.3