Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
achun opened this issue Jun 3, 2014 · 1 comment
Closed

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

achun opened this issue Jun 3, 2014 · 1 comment

Comments

@achun
Copy link

achun commented Jun 3, 2014

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.

@achun
Copy link
Author

achun commented Jun 15, 2014

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

@achun achun closed this as completed Jun 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant