mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
pre alloc capacity to improve structFields method
This commit is contained in:
parent
f51870e40e
commit
617419df6c
1 changed files with 5 additions and 3 deletions
|
|
@ -123,10 +123,11 @@ type field struct {
|
|||
}
|
||||
|
||||
// structFields resolves the typeinfo of all public fields in a struct type.
|
||||
func structFields(typ reflect.Type) (fields []field, err error) {
|
||||
func structFields(typ reflect.Type) ([]field, error) {
|
||||
// Convert fields to rlpstruct.Field.
|
||||
var allStructFields []rlpstruct.Field
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
n := typ.NumField()
|
||||
allStructFields := make([]rlpstruct.Field, n)
|
||||
for i := 0; i < n; i++ {
|
||||
rf := typ.Field(i)
|
||||
allStructFields = append(allStructFields, rlpstruct.Field{
|
||||
Name: rf.Name,
|
||||
|
|
@ -148,6 +149,7 @@ func structFields(typ reflect.Type) (fields []field, err error) {
|
|||
}
|
||||
|
||||
// Resolve typeinfo.
|
||||
fields := make([]field, 0, len(structFields))
|
||||
for i, sf := range structFields {
|
||||
typ := typ.Field(sf.Index).Type
|
||||
tags := structTags[i]
|
||||
|
|
|
|||
Loading…
Reference in a new issue