@@ -4,6 +4,7 @@ import (
44 "log/slog"
55 "os"
66 "path/filepath"
7+ "slices"
78 "strings"
89 "sync"
910
@@ -200,7 +201,7 @@ func (dl *directoryLister) getIgnore(path string) ignore.IgnoreParser {
200201
201202// ListDirectory lists files and directories in the specified path,
202203func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) {
203− var results []string
204+ results := csync.NewSlice[string]()
204205 truncated := false
205206 dl := NewDirectoryLister(initialPath)
206207
@@ -227,19 +228,19 @@ func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]st
227228 if d.IsDir() {
228229 path = path + string(filepath.Separator)
229230 }
230− results = append(results, path)
231+ results.Append(path)
231232 }
232233
233− if limit > 0 && len(results) >= limit {
234+ if limit > 0 && results.Len() >= limit {
234235 truncated = true
235236 return filepath.SkipAll
236237 }
237238
238239 return nil
239240 })
240− if err != nil && len(results) == 0 {
241+ if err != nil && results.Len() == 0 {
241242 return nil, truncated, err
242243 }
243244
244− return results, truncated, nil
245+ return slices.Collect(results.Seq()), truncated, nil
245246}