Merge pull request #12894 from jkschneider:webmvc-tags-perf

* pr/12894:
  Polish "Less object instantiation in WebMvcTags"
  Less object instantiation in WebMvcTags
This commit is contained in:
Stephane Nicoll
2018-04-18 09:41:57 +02:00

View File

@@ -40,6 +40,14 @@ public final class WebMvcTags {
private static final Tag URI_REDIRECTION = Tag.of("uri", "REDIRECTION");
private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN");
private static final Tag EXCEPTION_NONE = Tag.of("exception", "None");
private static final Tag STATUS_UNKNOWN = Tag.of("status", "UNKNOWN");
private static final Tag METHOD_UNKNOWN = Tag.of("method", "UNKNOWN");
private WebMvcTags() {
}
@@ -50,8 +58,7 @@ public final class WebMvcTags {
* @return the method tag whose value is a capitalized method (e.g. GET).
*/
public static Tag method(HttpServletRequest request) {
return (request == null ? Tag.of("method", "UNKNOWN")
: Tag.of("method", request.getMethod()));
return (request == null ? METHOD_UNKNOWN : Tag.of("method", request.getMethod()));
}
/**
@@ -60,8 +67,8 @@ public final class WebMvcTags {
* @return the status tag derived from the status of the response
*/
public static Tag status(HttpServletResponse response) {
return (response == null ? Tag.of("status", "UNKNOWN")
: Tag.of("status", ((Integer) response.getStatus()).toString()));
return (response == null ? STATUS_UNKNOWN :
Tag.of("status", Integer.toString(response.getStatus())));
}
/**
@@ -91,7 +98,7 @@ public final class WebMvcTags {
String pathInfo = getPathInfo(request);
return Tag.of("uri", pathInfo.isEmpty() ? "root" : pathInfo);
}
return Tag.of("uri", "UNKNOWN");
return URI_UNKNOWN;
}
private static HttpStatus extractStatus(HttpServletResponse response) {
@@ -121,8 +128,9 @@ public final class WebMvcTags {
* @return the exception tag derived from the exception
*/
public static Tag exception(Throwable exception) {
return Tag.of("exception",
(exception == null ? "None" : exception.getClass().getSimpleName()));
return (exception != null
? Tag.of("exception", exception.getClass().getSimpleName())
: EXCEPTION_NONE);
}
}