File: unsafe.go

package info (click to toggle)
golang-github-segmentio-encoding 0.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,472 kB
  • sloc: makefile: 286
file content (24 lines) | stat: -rw-r--r-- 589 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package thrift

import (
	"reflect"
	"unsafe"
)

// typeID is used as key in encoder and decoder caches to enable using
// the optimize runtime.mapaccess2_fast64 function instead of the more
// expensive lookup if we were to use reflect.Type as map key.
//
// typeID holds the pointer to the reflect.Type value, which is unique
// in the program.
type typeID struct{ ptr unsafe.Pointer }

func makeTypeID(t reflect.Type) typeID {
	return typeID{
		ptr: (*[2]unsafe.Pointer)(unsafe.Pointer(&t))[1],
	}
}

func unsafeBytesToString(b []byte) string {
	return *(*string)(unsafe.Pointer(&b))
}