...

Source file src/github.com/pelletier/go-toml/v2/internal/danger/typeid.go

Documentation: github.com/pelletier/go-toml/v2/internal/danger

     1  package danger
     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  //
    15  // https://github.com/segmentio/encoding/blob/master/json/codec.go#L59-L61
    16  type TypeID unsafe.Pointer
    17  
    18  func MakeTypeID(t reflect.Type) TypeID {
    19  	// reflect.Type has the fields:
    20  	// typ unsafe.Pointer
    21  	// ptr unsafe.Pointer
    22  	return TypeID((*[2]unsafe.Pointer)(unsafe.Pointer(&t))[1])
    23  }
    24  

View as plain text