From 189a811da5f106bbd676f8b6f6745104e36bde6c Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Wed, 19 Aug 2020 12:14:25 +0200 Subject: [PATCH] pre-allocate record slices --- pkg/store/filesystem/bundles.go | 4 ++-- pkg/store/filesystem/values.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/store/filesystem/bundles.go b/pkg/store/filesystem/bundles.go index e088e8a7e2..554d6c0b4f 100644 --- a/pkg/store/filesystem/bundles.go +++ b/pkg/store/filesystem/bundles.go @@ -20,13 +20,13 @@ func (s Store) ListBundles(bundleType proto.Bundle_Type) ([]*proto.Bundle, error m.RLock() defer m.RUnlock() - var records []*proto.Bundle bundlesFolder := s.buildFolderPathForBundles(false) bundleFiles, err := ioutil.ReadDir(bundlesFolder) if err != nil { - return records, nil + return []*proto.Bundle{}, nil } + records := make([]*proto.Bundle, 0, len(bundleFiles)) for _, bundleFile := range bundleFiles { record := proto.Bundle{} err = s.parseRecordFromFile(&record, filepath.Join(bundlesFolder, bundleFile.Name())) diff --git a/pkg/store/filesystem/values.go b/pkg/store/filesystem/values.go index 6336ec2eb1..93383a2453 100644 --- a/pkg/store/filesystem/values.go +++ b/pkg/store/filesystem/values.go @@ -14,13 +14,13 @@ import ( // If the accountUUID is empty, only values with empty accountUUID are returned. // If the accountUUID is not empty, values with an empty or with a matching accountUUID are returned. func (s Store) ListValues(bundleID, accountUUID string) ([]*proto.Value, error) { - var records []*proto.Value valuesFolder := s.buildFolderPathForValues(false) valueFiles, err := ioutil.ReadDir(valuesFolder) if err != nil { - return records, nil + return []*proto.Value{}, nil } + records := make([]*proto.Value, 0, len(valueFiles)) for _, valueFile := range valueFiles { record := proto.Value{} err := s.parseRecordFromFile(&record, filepath.Join(valuesFolder, valueFile.Name()))