| 1 |
package thrift |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"unsafe" |
| 6 |
) |
| 7 |
|
| 8 |
// typeID is used as key in encoder and decoder caches to enable using |
| 9 |
// the optimize runtime.mapaccess2_fast64 function instead of the more |
| 10 |
// expensive lookup if we were to use reflect.Type as map key. |
| 11 |
// |
| 12 |
// typeID holds the pointer to the reflect.Type value, which is unique |
| 13 |
// in the program. |
| 14 |
type typeID struct{ ptr unsafe.Pointer } |
| 15 |
|
| 16 |
func makeTypeID(t reflect.Type) typeID { |
| 17 |
return typeID{ |
| 18 |
ptr: (*[2]unsafe.Pointer)(unsafe.Pointer(&t))[1], |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
func unsafeBytesToString(b []byte) string { |
| 23 |
return *(*string)(unsafe.Pointer(&b)) |
| 24 |
} |