Skip to content

Commit

Permalink
Fix LOGBACK-1409 FileFilterUtil performance
Browse files Browse the repository at this point in the history
FileFilterUtil.filesInFolderMatchingStemRegex resuses compiled pattern
to avoid expensive regex recompilation for each file comparison.

Signed-off-by: David Schlosnagle <davids@palantir.com>
  • Loading branch information
schlosna committed Aug 22, 2022
1 parent 475281b commit ac823db
Showing 1 changed file with 3 additions and 5 deletions.
Expand Up @@ -79,11 +79,9 @@ public static File[] filesInFolderMatchingStemRegex(File file, final String stem
if (!file.exists() || !file.isDirectory()) {
return new File[0];
}
return file.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.matches(stemRegex);
}
});

Pattern regex = Pattern.compile(stemRegex);
return file.listFiles((dir, name) -> regex.matcher(name).matches());
}

static public int findHighestCounter(File[] matchingFileArray, final String stemRegex) {
Expand Down

0 comments on commit ac823db

Please sign in to comment.