Skip to content

Commit

Permalink
nonmem: avoid repeating a ReadDir call
Browse files Browse the repository at this point in the history
filesToCleanup() calls afero.ReadDir() on the output directory for
each pattern in parallelRegexesToRemove.  The directory files aren't
expected to change across iterations, so move the ReadDir() call
outside the regex for loop.
  • Loading branch information
kyleam committed Sep 22, 2023
1 parent 8c65e31 commit 94793a9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmd/nonmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,14 @@ func filesToCleanup(model *NonMemModel, exceptions ...string) runner.FileCleanIn

if model.Configuration.Parallel {
fs := afero.NewOsFs()
for _, variant := range parallelRegexesToRemove {
r := regexp.MustCompile(variant)
files, err := afero.ReadDir(fs, model.OutputDir)

files, err := afero.ReadDir(fs, model.OutputDir)
if err != nil {
log.Printf("Error trying to read directory %s for parallel files to cleanup", model.OutputDir)
}

if err != nil {
log.Printf("Error trying to read directory %s for parallel files to cleanup", model.OutputDir)
}
for _, variant := range parallelRegexesToRemove {
r := regexp.MustCompile(variant)

for _, f := range files {
if r.MatchString(f.Name()) {
Expand Down

0 comments on commit 94793a9

Please sign in to comment.