lunixbochs / struc

Better binary packing for Go
MIT License
564 stars 42 forks source link

use premade functions for common types #36

Open lunixbochs opened 8 years ago

lunixbochs commented 8 years ago

Take the signature/method examples from https://github.com/lunixbochs/struc/issues/35#issuecomment-180631405

This should result in a very good speedup without resorting to dynamically generated code yet, as we can cache function pointers with correct types.

For alternate number types like int struc:"uint32", we can use a lookup table to generate conversions like this:

switch outer {
    case int:
        return func(i int) uint32 {
            return uint32(i)
        }
}

Or take the argjoy approach of IntToInt and see if type switching is still faster than outright reflection.