aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-12-21 13:35:04 +0100
committerJon Marius Venstad <venstad@gmail.com>2020-12-21 13:35:04 +0100
commitf8fe4b41791bb52e5d0c256a8a5b6e9d493d8378 (patch)
treeaf816568e85786d890c0516a5e5f24f950630be7 /jdisc_core
parent9dc52312a5cd10d79cad13634381ea1eb5c7f0d3 (diff)
Reorder match order
Diffstat (limited to 'jdisc_core')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java
index aedd641a785..0a85bf6a403 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java
@@ -94,25 +94,24 @@ public class UriPattern implements Comparable<UriPattern> {
* @return A {@link Match} object describing the match found, or null if not found.
*/
public Match match(URI uri) {
- // Performance optimization: match path first since scheme and host are often the same in a given binding repository.
+ // Performance optimization: match in order of increasing cost and decreasing discriminating power.
+ if (port > 0 && port != uri.getPort())
+ return null;
+
String uriPath = nonNullOrBlank(uri.getPath());
GlobPattern.Match pathMatch = path.match(uriPath, uriPath.startsWith("/") ? 1 : 0);
- if (pathMatch == null) {
- return null;
- }
- if (port > 0 && port != uri.getPort()) {
- return null;
- }
- // Match scheme before host because it has a higher chance of differing (e.g. http versus https)
- GlobPattern.Match schemeMatch = scheme.match(normalizeScheme(nonNullOrBlank(uri.getScheme())));
- if (schemeMatch == null) {
+ if (pathMatch == null)
return null;
- }
+
GlobPattern.Match hostMatch = uri.getHost() == null ? null
: host.match(uri.getHost());
- if (hostMatch == null) {
+ if (hostMatch == null)
return null;
- }
+
+ GlobPattern.Match schemeMatch = scheme.match(normalizeScheme(nonNullOrBlank(uri.getScheme())));
+ if (schemeMatch == null)
+ return null;
+
return new Match(schemeMatch, hostMatch, port > 0 ? 0 : uri.getPort(), pathMatch);
}