codegangsta/inject

Maybe it's better this way, rtype.hash used as map keys

Closed this issue · 1 comments

my english is not good enough.

in package reflect

type rtype struct {
    size          uintptr        // size in bytes
    hash          uint32      // hash of type; avoids computation in hash tables
    _             uint8          // unused/padding
    align         uint8         // alignment of variable with this type
    fieldAlign    uint8       // alignment of struct field with this type
    kind          uint8         // enumeration for C
    alg           *uintptr      // algorithm table (../runtime/runtime.h:/Alg)
    gc            unsafe.Pointer // garbage collection data
    string        *string        // string form; unnecessary but undeniably useful
    *uncommonType                // (relatively) uncommon fields
    ptrToThis     *rtype         // type for pointer to this type, if used in binary or has methods
}
type emptyInterface struct {
    typ  *rtype
    word iword
}
func TypeOf(i interface{}) Type {
    eface := *(*emptyInterface)(unsafe.Pointer(&i))
    return toType(eface.typ)
}

Why not use this code for injector, and rtype.hash used as map keys?
uint32 used as map keys is faster more than reflect.Type.

That Is Not a Good Idea.
hash map collision problems.
https://codereview.appspot.com/6306083/#ps2001