Optimize single PathPattern match

Closes gh-36275
This commit is contained in:
rstoyanchev
2026-02-09 16:33:22 +00:00
parent 849553dc8e
commit 5c537db2cc
2 changed files with 9 additions and 3 deletions
@@ -157,13 +157,16 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
@Override
@Nullable
public PatternsRequestCondition getMatchingCondition(ServerWebExchange exchange) {
SortedSet<PathPattern> matches = getMatchingPatterns(exchange);
PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
if (this.patterns.size() == 1) {
return (this.patterns.first().matches(lookupPath) ? this : null);
}
SortedSet<PathPattern> matches = getMatchingPatterns(lookupPath);
return (matches != null ? new PatternsRequestCondition(matches) : null);
}
@Nullable
private SortedSet<PathPattern> getMatchingPatterns(ServerWebExchange exchange) {
PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
private SortedSet<PathPattern> getMatchingPatterns(PathContainer lookupPath) {
TreeSet<PathPattern> result = null;
for (PathPattern pattern : this.patterns) {
if (pattern.matches(lookupPath)) {
@@ -190,6 +190,9 @@ public final class PathPatternsRequestCondition extends AbstractRequestCondition
@Nullable
public PathPatternsRequestCondition getMatchingCondition(HttpServletRequest request) {
PathContainer path = ServletRequestPathUtils.getParsedRequestPath(request).pathWithinApplication();
if (this.patterns.size() == 1) {
return (this.patterns.first().matches(path) ? this : null);
}
SortedSet<PathPattern> matches = getMatchingPatterns(path);
return (matches != null ? new PathPatternsRequestCondition(matches) : null);
}