Use StringBuilder.append(char) where possible
To slightly improve performance, this commit switches to StringBuilder.append(char) instead of StringBuilder.append(String) whenever we append a single character to a StringBuilder. Closes gh-27098
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -147,7 +147,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
||||
for (String line : lines) {
|
||||
if (line.startsWith("data:")) {
|
||||
data = (data != null ? data : new StringBuilder());
|
||||
data.append(line.substring(5).trim()).append("\n");
|
||||
data.append(line.substring(5).trim()).append('\n');
|
||||
}
|
||||
if (shouldWrap) {
|
||||
if (line.startsWith("id:")) {
|
||||
@@ -161,7 +161,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
||||
}
|
||||
else if (line.startsWith(":")) {
|
||||
comment = (comment != null ? comment : new StringBuilder());
|
||||
comment.append(line.substring(1).trim()).append("\n");
|
||||
comment.append(line.substring(1).trim()).append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
|
||||
writeField("retry", retry.toMillis(), sb);
|
||||
}
|
||||
if (comment != null) {
|
||||
sb.append(':').append(StringUtils.replace(comment, "\n", "\n:")).append("\n");
|
||||
sb.append(':').append(StringUtils.replace(comment, "\n", "\n:")).append('\n');
|
||||
}
|
||||
if (data != null) {
|
||||
sb.append("data:");
|
||||
@@ -181,7 +181,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
|
||||
}
|
||||
|
||||
private void writeField(String fieldName, Object fieldValue, StringBuilder sb) {
|
||||
sb.append(fieldName).append(':').append(fieldValue).append("\n");
|
||||
sb.append(fieldName).append(':').append(fieldValue).append('\n');
|
||||
}
|
||||
|
||||
private DataBuffer encodeText(CharSequence text, MediaType mediaType, DataBufferFactory bufferFactory) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,7 +64,7 @@ public class MethodArgumentNotValidException extends BindException {
|
||||
}
|
||||
sb.append(": ");
|
||||
for (ObjectError error : bindingResult.getAllErrors()) {
|
||||
sb.append("[").append(error).append("] ");
|
||||
sb.append('[').append(error).append("] ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,9 +77,9 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
|
||||
if (i > 0) {
|
||||
sb.append(" OR ");
|
||||
}
|
||||
sb.append("\"");
|
||||
sb.append('"');
|
||||
sb.append(StringUtils.arrayToDelimitedString(conditions, ", "));
|
||||
sb.append("\"");
|
||||
sb.append('"');
|
||||
i++;
|
||||
}
|
||||
sb.append(" not met for actual request parameters: ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -289,7 +289,7 @@ public class WebExchangeBindException extends ServerWebInputException implements
|
||||
.append(parameter.getExecutable().toGenericString())
|
||||
.append(", with ").append(this.bindingResult.getErrorCount()).append(" error(s): ");
|
||||
for (ObjectError error : this.bindingResult.getAllErrors()) {
|
||||
sb.append("[").append(error).append("] ");
|
||||
sb.append('[').append(error).append("] ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -322,7 +322,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
|
||||
protected String createMessage(HttpServletRequest request, String prefix, String suffix) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(prefix);
|
||||
msg.append(request.getMethod()).append(" ");
|
||||
msg.append(request.getMethod()).append(' ');
|
||||
msg.append(request.getRequestURI());
|
||||
|
||||
if (isIncludeQueryString()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -333,7 +333,7 @@ public class ModelAndViewContainer {
|
||||
StringBuilder sb = new StringBuilder("ModelAndViewContainer: ");
|
||||
if (!isRequestHandled()) {
|
||||
if (isViewReference()) {
|
||||
sb.append("reference to view with name '").append(this.view).append("'");
|
||||
sb.append("reference to view with name '").append(this.view).append('\'');
|
||||
}
|
||||
else {
|
||||
sb.append("View is [").append(this.view).append(']');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -159,12 +159,12 @@ class CaptureVariablePathElement extends PathElement {
|
||||
@Override
|
||||
public char[] getChars() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("{");
|
||||
b.append('{');
|
||||
b.append(this.variableName);
|
||||
if (this.constraintPattern != null) {
|
||||
b.append(":").append(this.constraintPattern.pattern());
|
||||
b.append(':').append(this.constraintPattern.pattern());
|
||||
}
|
||||
b.append("}");
|
||||
b.append('}');
|
||||
return b.toString().toCharArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user