pre-allocate record slices
This commit is contained in:
@@ -20,13 +20,13 @@ func (s Store) ListBundles(bundleType proto.Bundle_Type) ([]*proto.Bundle, error
|
|||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
|
|
||||||
var records []*proto.Bundle
|
|
||||||
bundlesFolder := s.buildFolderPathForBundles(false)
|
bundlesFolder := s.buildFolderPathForBundles(false)
|
||||||
bundleFiles, err := ioutil.ReadDir(bundlesFolder)
|
bundleFiles, err := ioutil.ReadDir(bundlesFolder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return records, nil
|
return []*proto.Bundle{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
records := make([]*proto.Bundle, 0, len(bundleFiles))
|
||||||
for _, bundleFile := range bundleFiles {
|
for _, bundleFile := range bundleFiles {
|
||||||
record := proto.Bundle{}
|
record := proto.Bundle{}
|
||||||
err = s.parseRecordFromFile(&record, filepath.Join(bundlesFolder, bundleFile.Name()))
|
err = s.parseRecordFromFile(&record, filepath.Join(bundlesFolder, bundleFile.Name()))
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ import (
|
|||||||
// If the accountUUID is empty, only values with empty accountUUID are returned.
|
// 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.
|
// 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) {
|
func (s Store) ListValues(bundleID, accountUUID string) ([]*proto.Value, error) {
|
||||||
var records []*proto.Value
|
|
||||||
valuesFolder := s.buildFolderPathForValues(false)
|
valuesFolder := s.buildFolderPathForValues(false)
|
||||||
valueFiles, err := ioutil.ReadDir(valuesFolder)
|
valueFiles, err := ioutil.ReadDir(valuesFolder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return records, nil
|
return []*proto.Value{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
records := make([]*proto.Value, 0, len(valueFiles))
|
||||||
for _, valueFile := range valueFiles {
|
for _, valueFile := range valueFiles {
|
||||||
record := proto.Value{}
|
record := proto.Value{}
|
||||||
err := s.parseRecordFromFile(&record, filepath.Join(valuesFolder, valueFile.Name()))
|
err := s.parseRecordFromFile(&record, filepath.Join(valuesFolder, valueFile.Name()))
|
||||||
|
|||||||
Reference in New Issue
Block a user