Documentation ¶
Overview ¶
Package gohacks contains utilities for subverting the Go compiler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ImmutableBytesFromString ¶
ImmutableBytesFromString is equivalent to []byte(s), except that it uses the same memory backing s instead of making a heap-allocated copy. This is only valid if the returned slice is never mutated.
func Noescape ¶
Noescape hides a pointer from escape analysis. Noescape is the identity function but escape analysis doesn't think the output depends on the input. Noescape is inlined and currently compiles down to zero instructions. USE CAREFULLY!
Noescape is copy/pasted from Go's runtime/stubs.go:noescape(), and is valid as of Go 1.20. It is possible that this approach stops working in future versions of the toolchain, at which point `p` may still escape.
func Slice ¶
Slice returns a slice whose underlying array starts at ptr an which length and capacity are len.
Slice is a wrapper around unsafe.Slice. Prefer to use unsafe.Slice directly if possible.
func StringFromImmutableBytes ¶
StringFromImmutableBytes is equivalent to string(bs), except that it uses the same memory backing bs instead of making a heap-allocated copy. This is only valid if bs is never mutated after StringFromImmutableBytes returns.
Types ¶
This section is empty.