github.com/nikandfor/hacked@v0.0.0-20231207014854-3b383967fdf4/hruntime/low.go (about)

     1  package hruntime
     2  
     3  import "unsafe"
     4  
     5  //go:linkname Fastrand runtime.fastrand
     6  
     7  // Fastrand is runtime.fastrand.
     8  func Fastrand() uint32
     9  
    10  //go:noescape
    11  //go:linkname strhash runtime.strhash
    12  func strhash(p unsafe.Pointer, h uintptr) uintptr
    13  
    14  //go:noescape
    15  //go:linkname MemHash runtime.memhash
    16  
    17  // MemHash is fast builtin hash function.
    18  func MemHash(p unsafe.Pointer, h, size uintptr) uintptr
    19  
    20  //go:noescape
    21  //go:linkname MemHash64 runtime.memhash64
    22  
    23  // MemHash64 is fast builtin hash function.
    24  func MemHash64(p unsafe.Pointer, h uintptr) uintptr
    25  
    26  //go:noescape
    27  //go:linkname MemHash32 runtime.memhash32
    28  
    29  // MemHash32 is fast builtin hash function.
    30  func MemHash32(p unsafe.Pointer, h uintptr) uintptr
    31  
    32  // StrHash is fast builtin hash function.
    33  func StrHash(s string, h uintptr) uintptr {
    34  	return strhash(unsafe.Pointer(&s), h)
    35  }
    36  
    37  // BytesHash is fast builtin hash function.
    38  func BytesHash(s []byte, h uintptr) uintptr {
    39  	return strhash(unsafe.Pointer(&s), h)
    40  }
    41  
    42  type eface struct {
    43  	t, p unsafe.Pointer
    44  }
    45  
    46  func Nil(v interface{}) bool {
    47  	e := *(*eface)(unsafe.Pointer(&v))
    48  
    49  	return e.t == nil || e.p == nil
    50  }
    51  
    52  func Interface(v interface{}) (typ, data unsafe.Pointer) {
    53  	i := ((*eface)(unsafe.Pointer(&v)))
    54  	return i.t, i.p
    55  }