Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public class SafeRegex {
.build();


private record CachedGlobResult(@Nullable String regex, @Nullable PatternSyntaxException error) {}
private record CachedGlobResult(@Nullable String regex, @Nullable PatternSyntaxException error) {
public boolean isError() {
return this.error != null;
}
}

private record CachedReplacementResult(@Nullable PatternSyntaxException error) {
boolean isError() { return this.error != null; }
Expand Down Expand Up @@ -154,6 +158,21 @@ public static void assertReplacementSafe(@NotNull String regex, @NotNull String
throw cached.error;
}

@NotNull
private static CachedRegexResult processRegex(@NotNull CachedGlobResult cachedResult) {
CachedRegexResult cached;

if (cachedResult.isError()) { // return a cached regex result with the error from cachedResult
cached = new CachedRegexResult(cachedResult.error);
} else {
String regex = cachedResult.regex;

cached = processRegex(regex);
}

return cached;
}

@NotNull
private static CachedRegexResult processRegex(@NotNull String regex) {
CachedRegexResult cached = REGEX_CACHE.getIfPresent(regex);
Expand Down Expand Up @@ -217,7 +236,7 @@ public static boolean isSafe(String regex, int starHeightLimit, int repetitionLi

}

private static String cachedToRegexPattern(String address) {
private static CachedGlobResult cachedToRegexPattern(String address) {
var cached = GLOB_CACHE.getIfPresent(address);
if (cached == null) {
try {
Expand All @@ -228,7 +247,7 @@ private static String cachedToRegexPattern(String address) {
GLOB_CACHE.put(address, cached);
}

return cached.regex;
return cached;
}

/// An optimized version of PackageItem.matchAddress that uses caching and optimized logic.
Expand Down Expand Up @@ -261,4 +280,4 @@ else if (info.pattern != null && info.pattern.matcher(address).matches())
return false;
}

}
}