1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:10:12 -07:00

reflect: add fast path for FieldByIndex with len(index) = 1

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/152640043
This commit is contained in:
Russ Cox 2014-10-15 13:33:00 -04:00
parent cb6f5ac0b0
commit 94950afdf8

View File

@ -857,6 +857,9 @@ func (v Value) Field(i int) Value {
// FieldByIndex returns the nested field corresponding to index.
// It panics if v's Kind is not struct.
func (v Value) FieldByIndex(index []int) Value {
if len(index) == 1 {
return v.Field(index[0])
}
v.mustBe(Struct)
for i, x := range index {
if i > 0 {