gohacks

package
v0.0.0-...-c27c9a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2024 License: Apache-2.0, MIT Imports: 1 Imported by: 36

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

func ImmutableBytesFromString(s string) []byte

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 Memmove

func Memmove(to, from unsafe.Pointer, n uintptr)

Memmove is runtime.memmove, exported for SeqAtomicLoad/SeqAtomicTryLoad<T>.

func Nanotime

func Nanotime() int64

Nanotime is runtime.nanotime.

func Noescape

func Noescape(p unsafe.Pointer) unsafe.Pointer

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

func Slice[T any](ptr *T, length int) []T

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

func StringFromImmutableBytes(bs []byte) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL