Optimize performance of produces condition checks

This commit is contained in:
wenqi.huang 2019-03-22 22:09:04 +08:00 committed by Rossen Stoyanchev
parent d4714847a0
commit d10174a3e9
3 changed files with 49 additions and 16 deletions

View File

@ -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 {
}
}
@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);

View File

@ -216,20 +216,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange);
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
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 (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange);
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;

View File

@ -217,20 +217,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
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 (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
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;