mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Optimize single PathPattern match
Closes gh-36275
This commit is contained in:
+6
-3
@@ -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)) {
|
||||
|
||||
+3
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user