From 8e4f5dd97ba1941b6b4f6e2fef8e21485ff9c8b9 Mon Sep 17 00:00:00 2001 From: Suhail Patel Date: Sun, 23 Jun 2019 23:16:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=85=20Pre-allocate=20size=20of=20the?= =?UTF-8?q?=20list=20for=20struct=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scanner.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scanner.go b/scanner.go index 766f458..e66233d 100644 --- a/scanner.go +++ b/scanner.go @@ -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