Commit 94950afd authored by Russ Cox's avatar Russ Cox

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

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/152640043
parent cb6f5ac0
...@@ -857,6 +857,9 @@ func (v Value) Field(i int) Value { ...@@ -857,6 +857,9 @@ func (v Value) Field(i int) Value {
// FieldByIndex returns the nested field corresponding to index. // FieldByIndex returns the nested field corresponding to index.
// It panics if v's Kind is not struct. // It panics if v's Kind is not struct.
func (v Value) FieldByIndex(index []int) Value { func (v Value) FieldByIndex(index []int) Value {
if len(index) == 1 {
return v.Field(index[0])
}
v.mustBe(Struct) v.mustBe(Struct)
for i, x := range index { for i, x := range index {
if i > 0 { if i > 0 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment