mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Optimize single PathPattern match
Closes gh-36275
This commit is contained in:
+6
-3
@@ -157,12 +157,15 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
*/
|
||||
@Override
|
||||
public @Nullable 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);
|
||||
}
|
||||
|
||||
private @Nullable SortedSet<PathPattern> getMatchingPatterns(ServerWebExchange exchange) {
|
||||
PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
|
||||
private @Nullable SortedSet<PathPattern> getMatchingPatterns(PathContainer lookupPath) {
|
||||
TreeSet<PathPattern> result = null;
|
||||
for (PathPattern pattern : this.patterns) {
|
||||
if (pattern.matches(lookupPath)) {
|
||||
|
||||
+3
@@ -189,6 +189,9 @@ public final class PathPatternsRequestCondition extends AbstractRequestCondition
|
||||
@Override
|
||||
public @Nullable 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