preallocate array

This commit is contained in:
Shreyas Goenka 2023-05-26 13:02:50 +02:00
parent 8a9175e332
commit 7c46b35597
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 8 additions and 8 deletions

View File

@ -143,14 +143,14 @@ func (w *WorkspaceFilesClient) ReadDir(ctx context.Context, name string) ([]File
return nil, err
}
info := make([]FileInfo, 0)
for _, i := range objects {
info = append(info, FileInfo{
Type: string(i.ObjectType),
Name: path.Base(i.Path),
Size: i.Size,
ModTime: time.UnixMilli(i.ModifiedAt),
})
info := make([]FileInfo, len(objects))
for i, v := range objects {
info[i] = FileInfo{
Type: string(v.ObjectType),
Name: path.Base(v.Path),
Size: v.Size,
ModTime: time.UnixMilli(v.ModifiedAt),
}
}
return info, nil
}