|
|
il y a 7 ans | |
|---|---|---|
| test15 | il y a 7 ans | |
| tests | il y a 7 ans | |
| .gitignore | il y a 7 ans | |
| .travis.yml | il y a 7 ans | |
| Gopkg.lock | il y a 7 ans | |
| Gopkg.toml | il y a 7 ans | |
| LICENSE | il y a 7 ans | |
| README.md | il y a 7 ans | |
| go_above_17.go | il y a 7 ans | |
| go_above_19.go | il y a 7 ans | |
| go_below_17.go | il y a 7 ans | |
| go_below_19.go | il y a 7 ans | |
| reflect2.go | il y a 7 ans | |
| reflect2_amd64.s | il y a 7 ans | |
| reflect2_kind.go | il y a 7 ans | |
| relfect2_386.s | il y a 7 ans | |
| relfect2_amd64p32.s | il y a 7 ans | |
| relfect2_arm.s | il y a 7 ans | |
| relfect2_arm64.s | il y a 7 ans | |
| relfect2_mips64x.s | il y a 7 ans | |
| relfect2_mipsx.s | il y a 7 ans | |
| relfect2_ppc64x.s | il y a 7 ans | |
| relfect2_s390x.s | il y a 7 ans | |
| safe_field.go | il y a 7 ans | |
| safe_map.go | il y a 7 ans | |
| safe_slice.go | il y a 7 ans | |
| safe_struct.go | il y a 7 ans | |
| safe_type.go | il y a 7 ans | |
| test.sh | il y a 7 ans | |
| type_map.go | il y a 7 ans | |
| type_map_test.go | il y a 7 ans | |
| unsafe_array.go | il y a 7 ans | |
| unsafe_eface.go | il y a 7 ans | |
| unsafe_field.go | il y a 7 ans | |
| unsafe_iface.go | il y a 7 ans | |
| unsafe_link.go | il y a 7 ans | |
| unsafe_map.go | il y a 7 ans | |
| unsafe_ptr.go | il y a 7 ans | |
| unsafe_slice.go | il y a 7 ans | |
| unsafe_struct.go | il y a 7 ans | |
| unsafe_type.go | il y a 7 ans |
reflect api that avoids runtime reflect.Value cost
reflect2.TypeByName works like Class.forName found in javajson-iterator use this package to save runtime dispatching cost. This package is designed for low level libraries to optimize reflection performance. General application should still use reflect standard library.
// given package is github.com/your/awesome-package
type MyStruct struct {
// ...
}
// will return the type
reflect2.TypeByName("awesome-package.MyStruct")
// however, if the type has not been used
// it will be eliminated by compiler, so we can not get it in runtime
valType := reflect2.TypeOf(1)
i := 1
j := 10
valType.Set(&i, &j)
// i will be 10
valType := reflect2.TypeOf(1)
i := 1
j := 10
valType.UnsafeSet(unsfae.Pointer(&i), unsafe.Pointer(&j))
// i will be 10