Skip to content

Commit 0b02c0c

Browse files
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).
1 parent ae64dae commit 0b02c0c

1 file changed

Lines changed: 0 additions & 34 deletions

File tree

internal/tarfs/tarfs.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ package tarfs
1717
import (
1818
"archive/tar"
1919
"bufio"
20-
"cmp"
2120
"errors"
2221
"fmt"
2322
"io"
2423
"io/fs"
2524
"path"
26-
"slices"
2725
"sync"
2826
"time"
2927
)
@@ -98,7 +96,6 @@ type FS struct {
9896
ra io.ReaderAt
9997
files []*Entry
10098
index map[string]int
101-
dirs map[string][]fs.DirEntry
10299
}
103100

104101
func (fsys *FS) Readlink(name string) (string, error) {
@@ -184,15 +181,6 @@ func (fsys *FS) Stat(name string) (fs.FileInfo, error) {
184181
return nil, fs.ErrNotExist
185182
}
186183

187-
func (fsys *FS) ReadDir(name string) ([]fs.DirEntry, error) {
188-
dirs, ok := fsys.dirs[name]
189-
if !ok {
190-
return []fs.DirEntry{}, nil
191-
}
192-
193-
return dirs, nil
194-
}
195-
196184
type countReader struct {
197185
r io.Reader
198186
n int64
@@ -209,12 +197,8 @@ func New(ra io.ReaderAt, size int64) (*FS, error) {
209197
ra: ra,
210198
files: []*Entry{},
211199
index: map[string]int{},
212-
dirs: map[string][]fs.DirEntry{},
213200
}
214201

215-
// Number of entries in a given directory, so we know how large of a slice to allocate.
216-
dirCount := map[string]int{}
217-
218202
// TODO: Consider caching this across builds.
219203
r := io.NewSectionReader(ra, 0, size)
220204

@@ -239,24 +223,6 @@ func New(ra io.ReaderAt, size int64) (*FS, error) {
239223
dir: dir,
240224
fi: hdr.FileInfo(),
241225
})
242-
243-
dirCount[dir]++
244-
}
245-
246-
// Pre-generate the results of ReadDir so we don't allocate a ton if fs.WalkDir calls us.
247-
// TODO: Consider doing this lazily in a sync.Once the first time we see a ReadDir.
248-
for dir, count := range dirCount {
249-
fsys.dirs[dir] = make([]fs.DirEntry, 0, count)
250-
}
251-
252-
for _, f := range fsys.files {
253-
fsys.dirs[f.dir] = append(fsys.dirs[f.dir], f)
254-
}
255-
256-
for _, files := range fsys.dirs {
257-
slices.SortFunc(files, func(a, b fs.DirEntry) int {
258-
return cmp.Compare(a.Name(), b.Name())
259-
})
260226
}
261227

262228
return fsys, nil

0 commit comments

Comments
 (0)