From 0b02c0cdb647a8a0e28c0c7e72f4293800db8970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Thu, 15 Jan 2026 19:26:03 +0100 Subject: [PATCH] Simplify tarfs by removing unnessary functions We're only accessing `Entries` and files directly anyway so we don't really need the `ReadDir` semantics and the sorting cost that comes with that (alongside random access). --- internal/tarfs/tarfs.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/internal/tarfs/tarfs.go b/internal/tarfs/tarfs.go index f8584a6cf..a9fcd24d9 100644 --- a/internal/tarfs/tarfs.go +++ b/internal/tarfs/tarfs.go @@ -17,13 +17,11 @@ package tarfs import ( "archive/tar" "bufio" - "cmp" "errors" "fmt" "io" "io/fs" "path" - "slices" "sync" "time" ) @@ -98,7 +96,6 @@ type FS struct { ra io.ReaderAt files []*Entry index map[string]int - dirs map[string][]fs.DirEntry } func (fsys *FS) Readlink(name string) (string, error) { @@ -184,15 +181,6 @@ func (fsys *FS) Stat(name string) (fs.FileInfo, error) { return nil, fs.ErrNotExist } -func (fsys *FS) ReadDir(name string) ([]fs.DirEntry, error) { - dirs, ok := fsys.dirs[name] - if !ok { - return []fs.DirEntry{}, nil - } - - return dirs, nil -} - type countReader struct { r io.Reader n int64 @@ -209,12 +197,8 @@ func New(ra io.ReaderAt, size int64) (*FS, error) { ra: ra, files: []*Entry{}, index: map[string]int{}, - dirs: map[string][]fs.DirEntry{}, } - // Number of entries in a given directory, so we know how large of a slice to allocate. - dirCount := map[string]int{} - // TODO: Consider caching this across builds. r := io.NewSectionReader(ra, 0, size) @@ -239,24 +223,6 @@ func New(ra io.ReaderAt, size int64) (*FS, error) { dir: dir, fi: hdr.FileInfo(), }) - - dirCount[dir]++ - } - - // Pre-generate the results of ReadDir so we don't allocate a ton if fs.WalkDir calls us. - // TODO: Consider doing this lazily in a sync.Once the first time we see a ReadDir. - for dir, count := range dirCount { - fsys.dirs[dir] = make([]fs.DirEntry, 0, count) - } - - for _, f := range fsys.files { - fsys.dirs[f.dir] = append(fsys.dirs[f.dir], f) - } - - for _, files := range fsys.dirs { - slices.SortFunc(files, func(a, b fs.DirEntry) int { - return cmp.Compare(a.Name(), b.Name()) - }) } return fsys, nil