gohacks

package
v0.0.0-...-6a88ae7 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: Apache-2.0, MIT Imports: 1 Imported by: 0

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) (bs []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 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().)

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

type SliceHeader

type SliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

SliceHeader is equivalent to reflect.SliceHeader, but represents the pointer to the underlying array as unsafe.Pointer rather than uintptr, allowing SliceHeaders to be directly converted to slice objects.

type StringHeader

type StringHeader struct {
	Data unsafe.Pointer
	Len  int
}

StringHeader is equivalent to reflect.StringHeader, but represents the pointer to the underlying array as unsafe.Pointer rather than uintptr, allowing StringHeaders to be directly converted to strings.

Jump to

Keyboard shortcuts

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