[logback-dev] [JIRA] (LOGBACK-1409) Compile and reuse a Pattern in FileFilterUtil.computeCurrentPeriodsHighestCounterValue(String)

QOS.CH (JIRA) noreply-jira at qos.ch
Fri Jun 8 13:23:00 CEST 2018


Andy Wilkinson created LOGBACK-1409:
---------------------------------------

             Summary: Compile and reuse a Pattern in FileFilterUtil.computeCurrentPeriodsHighestCounterValue(String)
                 Key: LOGBACK-1409
                 URL: https://jira.qos.ch/browse/LOGBACK-1409
             Project: logback
          Issue Type: Improvement
          Components: logback-core
    Affects Versions: 1.2.3
            Reporter: Andy Wilkinson
            Assignee: Logback dev list
            Priority: Minor


{{FileFilterUtil.filesInFolderMatchingStemRegex(String)}} currently calls {{String.matches(stemRegex)}} once for each file or directory in the folder. The is inefficient and noticeably so for folders with large numbers of files as it causes the same {{Pattern}} to be compiled once for each file or directory in the folder. The repeat compilation could be avoided by performing it once outside of the filtering callback:

{code:java}
Pattern pattern = Pattern.compile(stemRegex);
return file.listFiles(new FilenameFilter() {
	@Override
	public boolean accept(File dir, String name) {
		return pattern.matcher(name).matches();
	}
});
{code}



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the logback-dev mailing list