Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
🦅 Pre-allocate size of the list for struct fields
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailpatel committed Jun 23, 2019
1 parent bb225dd commit 8e4f5dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func (s *scanner) structFields(structType reflect.Type) ([]*r.Field, error) {
return nil, fmt.Errorf("could not decode struct of type %T", fmPtr)
}

structFields := []*r.Field{}
for _, fieldName := range s.stmt.fieldNames {
structFields := make([]*r.Field, len(s.stmt.fieldNames))
for i, fieldName := range s.stmt.fieldNames {
field, ok := m[strings.ToLower(fieldName)]
if !ok { // the field doesn't have a destination
structFields = append(structFields, nil)
structFields[i] = nil
} else {
structFields = append(structFields, &field)
structFields[i] = &field
}
}
return structFields, nil
Expand Down

0 comments on commit 8e4f5dd

Please sign in to comment.