Change to Readdirnames for some cases

There was a couple uses of Readdir/ReadDir here where the only thing the return
value was used for was the Name of the entry. This is exactly what Readdirnames
returns, so we can avoid the overhead of making/returning a bunch of interfaces
and calling lstat everytime in the case of Readdir(-1).

https://cs.opensource.google/go/go/+/refs/tags/go1.20.4:src/os/dir_unix.go;l=114-137

Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
Danny Canter
2023-05-07 23:50:57 -07:00
parent 98f48d485d
commit f5211ee3fc
3 changed files with 33 additions and 12 deletions

View File

@@ -295,10 +295,9 @@ func (s *store) ListStatuses(ctx context.Context, fs ...string) ([]content.Statu
if err != nil {
return nil, err
}
defer fp.Close()
fis, err := fp.Readdir(-1)
fis, err := fp.Readdirnames(-1)
if err != nil {
return nil, err
}
@@ -310,7 +309,7 @@ func (s *store) ListStatuses(ctx context.Context, fs ...string) ([]content.Statu
var active []content.Status
for _, fi := range fis {
p := filepath.Join(s.root, "ingest", fi.Name())
p := filepath.Join(s.root, "ingest", fi)
stat, err := s.status(p)
if err != nil {
if !os.IsNotExist(err) {
@@ -345,16 +344,15 @@ func (s *store) WalkStatusRefs(ctx context.Context, fn func(string) error) error
if err != nil {
return err
}
defer fp.Close()
fis, err := fp.Readdir(-1)
fis, err := fp.Readdirnames(-1)
if err != nil {
return err
}
for _, fi := range fis {
rf := filepath.Join(s.root, "ingest", fi.Name(), "ref")
rf := filepath.Join(s.root, "ingest", fi, "ref")
ref, err := readFileString(rf)
if err != nil {