| commit | 58ce5d9ea2ba5d2b152df0eca46fffdec21bdee4 | [log] [tgz] |
|---|---|---|
| author | Tao Wen <taowen@gmail.com> | Thu Mar 01 10:08:14 2018 |
| committer | Tao Wen <taowen@gmail.com> | Thu Mar 01 10:08:14 2018 |
| tree | cd15b1b076c257de688c5209cfeec9706738e868 | |
| parent | e5182c85326b86a4e305cc188a0f9ad1de9de5e9 [diff] |
add README
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