github.com/webmafia/fast@v0.10.0/noescape.go (about) 1 package fast 2 3 import "unsafe" 4 5 // noescape hides a pointer from escape analysis. It is the identity function 6 // but escape analysis doesn't think the output depends on the input. 7 // noescape is inlined and currently compiles down to zero instructions. 8 // USE CAREFULLY! 9 // This was copied from the runtime; see issues 23382 and 7921. 10 // 11 //go:nosplit 12 //go:nocheckptr 13 func Noescape(p unsafe.Pointer) unsafe.Pointer { 14 x := uintptr(p) 15 return unsafe.Pointer(x ^ 0) 16 } 17 18 //go:inline 19 func NoescapeVal[T any](p *T) *T { 20 return (*T)(Noescape(unsafe.Pointer(p))) 21 } 22 23 //go:inline 24 func NoescapeBytes(b []byte) []byte { 25 return *(*[]byte)(Noescape(unsafe.Pointer(&b))) 26 }