added preallocation of size

This commit is contained in:
Shreyas Goenka 2023-06-05 15:09:09 +02:00
parent 265e517126
commit 08826094ce
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 3 additions and 3 deletions

View File

@ -59,13 +59,13 @@ var lsCmd = &cobra.Command{
return err
}
jsonDirEntries := make([]jsonDirEntry, 0)
for _, entry := range entries {
jsonDirEntries := make([]jsonDirEntry, len(entries))
for i, entry := range entries {
jsonDirEntry, err := toJsonDirEntry(entry)
if err != nil {
return err
}
jsonDirEntries = append(jsonDirEntries, *jsonDirEntry)
jsonDirEntries[i] = *jsonDirEntry
}
sort.Slice(jsonDirEntries, func(i, j int) bool {
return jsonDirEntries[i].Name < jsonDirEntries[j].Name