]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add fast path for FieldByIndex with len(index) = 1
authorRuss Cox <rsc@golang.org>
Wed, 15 Oct 2014 17:33:00 +0000 (13:33 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Oct 2014 17:33:00 +0000 (13:33 -0400)
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/152640043

src/reflect/value.go

index 9c65ee27033ceaf3d355e7adc96db4c5dbd90af8..8c320f11b06f7c1f346ecbce7209d324800fd27e 100644 (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 {