From d10174a3e9c54d1ed1e2b8d5725a1d0249375eff Mon Sep 17 00:00:00 2001 From: "wenqi.huang" Date: Fri, 22 Mar 2019 22:09:04 +0800 Subject: [PATCH] Optimize performance of produces condition checks --- .../http/ReadOnlyHttpHeaders.java | 15 +++++++++++++ .../result/method/RequestMappingInfo.java | 21 +++++++++++++------ .../mvc/method/RequestMappingInfo.java | 21 +++++++++++++------ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java b/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java index 341938f1ba..6fe96f0819 100644 --- a/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java @@ -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 getAccept() { + if (this.cachedAccept != null) { + return this.cachedAccept; + } + else { + List accept = super.getAccept(); + this.cachedAccept = accept; + return accept; + } + } + @Override public List get(Object key) { List values = this.headers.get(key); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java index 795dc53185..479fcbed15 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java @@ -216,20 +216,29 @@ public final class RequestMappingInfo implements RequestCondition