Polish "Add ServerWebExchange a new attribute for PathContainer to avoid repeating parsePath in PathRoutePredicateFactory."

See gh-2884
This commit is contained in:
spencergibb
2023-03-15 16:20:45 -04:00
parent 18e116c1c6
commit 5d8c2cf898
3 changed files with 9 additions and 7 deletions

View File

@@ -174,12 +174,13 @@
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.20</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -90,12 +90,9 @@ public class PathRoutePredicateFactory extends AbstractRoutePredicateFactory<Pat
return new GatewayPredicate() {
@Override
public boolean test(ServerWebExchange exchange) {
PathContainer path = (PathContainer) exchange.getAttributes()
.get(GATEWAY_PREDICATE_PATH_CONTAINER_ATTR);
if (path == null) {
path = parsePath(exchange.getRequest().getURI().getRawPath());
exchange.getAttributes().put(GATEWAY_PREDICATE_PATH_CONTAINER_ATTR, path);
}
PathContainer path = (PathContainer) exchange.getAttributes().computeIfAbsent(
GATEWAY_PREDICATE_PATH_CONTAINER_ATTR,
s -> parsePath(exchange.getRequest().getURI().getRawPath()));
PathPattern match = null;
for (int i = 0; i < pathPatterns.size(); i++) {

View File

@@ -75,4 +75,8 @@ public class PathRoutePredicatePathContainerAttrBenchMarkTests {
}
}
public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}
}