mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: fix FieldByNameFunc
The existing algorithm did not properly propagate the type count from one level to the next, and as a consequence it missed collisions. Properly propagate multiplicity (count) information to the next level. benchmark old ns/op new ns/op delta BenchmarkFieldByName1 182 180 -1.10% BenchmarkFieldByName2 6273 6183 -1.43% BenchmarkFieldByName3 49267 46784 -5.04% Fixes #4355. R=rsc CC=golang-dev https://golang.org/cl/6821094
This commit is contained in:
parent
2e77bc48aa
commit
aa38801788
2 changed files with 20 additions and 2 deletions
|
|
@ -1694,6 +1694,20 @@ type S13 struct {
|
|||
S8
|
||||
}
|
||||
|
||||
// The X in S15.S11.S1 and S16.S11.S1 annihilate.
|
||||
type S14 struct {
|
||||
S15
|
||||
S16
|
||||
}
|
||||
|
||||
type S15 struct {
|
||||
S11
|
||||
}
|
||||
|
||||
type S16 struct {
|
||||
S11
|
||||
}
|
||||
|
||||
var fieldTests = []FTest{
|
||||
{struct{}{}, "", nil, 0},
|
||||
{struct{}{}, "Foo", nil, 0},
|
||||
|
|
@ -1719,6 +1733,7 @@ var fieldTests = []FTest{
|
|||
{S5{}, "Y", []int{2, 0, 1}, 0},
|
||||
{S10{}, "X", nil, 0},
|
||||
{S10{}, "Y", []int{2, 0, 0, 1}, 0},
|
||||
{S14{}, "X", nil, 0},
|
||||
}
|
||||
|
||||
func TestFieldByIndex(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue