mirror of
https://github.com/golang/go
synced 2024-11-23 17:40:03 -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:
parent
cb6f5ac0b0
commit
94950afdf8
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user