Browse Source

Optimize performance of produces condition checks

pull/22667/head
wenqi.huang 7 years ago committed by Rossen Stoyanchev
parent
commit
d10174a3e9
  1. 15
      spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java
  2. 21
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java
  3. 21
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

15
spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java

@ -40,6 +40,9 @@ class ReadOnlyHttpHeaders extends HttpHeaders { @@ -40,6 +40,9 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
@Nullable
private MediaType cachedContentType;
@Nullable
private MediaType cachedAccept;
ReadOnlyHttpHeaders(HttpHeaders headers) {
super(headers.headers);
}
@ -56,6 +59,18 @@ class ReadOnlyHttpHeaders extends HttpHeaders { @@ -56,6 +59,18 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
}
}
@Override
public List<MediaType> getAccept() {
if (this.cachedAccept != null) {
return this.cachedAccept;
}
else {
List<MediaType> accept = super.getAccept();
this.cachedAccept = accept;
return accept;
}
}
@Override
public List<String> get(Object key) {
List<String> values = this.headers.get(key);

21
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java

@ -216,20 +216,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping @@ -216,20 +216,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange);
if (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange);
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);
if (methods == null || params == null || headers == null || consumes == null || produces == null) {
if (headers == null) {
return null;
}
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
if (patterns == null) {
return null;
}
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
if (consumes == null) {
return null;
}
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);
if (produces == null) {
return null;
}
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange);
if (custom == null) {
return null;

21
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

@ -217,20 +217,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping @@ -217,20 +217,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
if (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
if (methods == null || params == null || headers == null || consumes == null || produces == null) {
if (headers == null) {
return null;
}
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
if (patterns == null) {
return null;
}
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
if (consumes == null) {
return null;
}
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
if (produces == null) {
return null;
}
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);
if (custom == null) {
return null;

Loading…
Cancel
Save