pre-allocate record slices

This commit is contained in:
Benedikt Kulmann
2020-08-19 12:14:25 +02:00
parent d59cdd5469
commit 189a811da5
2 changed files with 4 additions and 4 deletions

View File

@@ -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()))

View File

@@ -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()))