Skip to content

Commit

Permalink
reflect: add fast path for FieldByIndex with len(index) = 1
Browse files Browse the repository at this point in the history
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/152640043
  • Loading branch information
rsc committed Oct 15, 2014
1 parent cb6f5ac commit 94950af
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 94950af

Please sign in to comment.