Skip to content

Commit b8f40f3

Browse files
⚡ Cache compiled regex patterns in TestFolderPathPattern
Implemented a static LRU cache for compiled regex patterns in the TestFolderPathPattern.resolveGroups method to avoid redundant compilation when processing multiple files in the same folders. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
1 parent 6210c73 commit b8f40f3

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

org.moreunit.core/src/org/moreunit/core/matching/TestFolderPathPattern.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
import java.util.regex.Pattern;
1717

1818
import org.moreunit.core.resources.Path;
19+
import org.moreunit.core.util.LRUCache;
1920
import org.moreunit.core.util.Strings;
2021

2122
public class TestFolderPathPattern
2223
{
24+
private static final Map<String, Pattern> PATTERN_CACHE = new LRUCache<String, Pattern>(50);
25+
2326
public static final String SRC_PROJECT_VARIABLE = "${srcProject}";
2427

2528
private static final int MAX_GROUPS = 9;
@@ -200,7 +203,18 @@ private String resolveGroups(String path, String tplWithGroups, String tplWithRe
200203
{
201204
String result = tplWithRefs;
202205

203-
Matcher matcher = Pattern.compile(tplWithGroups).matcher(path);
206+
Pattern pattern;
207+
synchronized (PATTERN_CACHE)
208+
{
209+
pattern = PATTERN_CACHE.get(tplWithGroups);
210+
if(pattern == null)
211+
{
212+
pattern = compile(tplWithGroups);
213+
PATTERN_CACHE.put(tplWithGroups, pattern);
214+
}
215+
}
216+
217+
Matcher matcher = pattern.matcher(path);
204218
if(matcher.matches())
205219
{
206220
List<GroupRef> groupRefs = getGroupRefs(result);

0 commit comments

Comments
 (0)