From 94950afdf8d94fd4ff3fba7e84bf4ce4b16854d0 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 15 Oct 2014 13:33:00 -0400 Subject: [PATCH] reflect: add fast path for FieldByIndex with len(index) = 1 LGTM=r R=r CC=golang-codereviews https://golang.org/cl/152640043 --- src/reflect/value.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/reflect/value.go b/src/reflect/value.go index 9c65ee27033..8c320f11b06 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -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 {