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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -111,7 +111,7 @@ public class HttpRangeTests {
|
||||
// 1. At limit..
|
||||
StringBuilder atLimit = new StringBuilder("bytes=0-0");
|
||||
for (int i=0; i < 99; i++) {
|
||||
atLimit.append(",").append(i).append("-").append(i + 1);
|
||||
atLimit.append(',').append(i).append('-').append(i + 1);
|
||||
}
|
||||
List<HttpRange> ranges = HttpRange.parseRanges(atLimit.toString());
|
||||
assertThat(ranges.size()).isEqualTo(100);
|
||||
@@ -119,7 +119,7 @@ public class HttpRangeTests {
|
||||
// 2. Above limit..
|
||||
StringBuilder aboveLimit = new StringBuilder("bytes=0-0");
|
||||
for (int i=0; i < 100; i++) {
|
||||
aboveLimit.append(",").append(i).append("-").append(i + 1);
|
||||
aboveLimit.append(',').append(i).append('-').append(i + 1);
|
||||
}
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
HttpRange.parseRanges(aboveLimit.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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.multipart.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -80,7 +81,7 @@ public class DefaultMultipartHttpServletRequestTests {
|
||||
for (String key : this.queryParams.keySet()) {
|
||||
for (String value : this.queryParams.get(key)) {
|
||||
this.servletRequest.addParameter(key, value);
|
||||
query.append(query.length() > 0 ? "&" : "").append(key).append("=").append(value);
|
||||
query.append(query.length() > 0 ? "&" : "").append(key).append('=').append(value);
|
||||
}
|
||||
}
|
||||
this.servletRequest.setQueryString(query.toString());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2019 the original author or authors.
|
||||
* Copyright 2004-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.
|
||||
@@ -33,15 +33,15 @@ public class JavaScriptUtilsTests {
|
||||
public void escape() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('"');
|
||||
sb.append("'");
|
||||
sb.append("\\");
|
||||
sb.append("/");
|
||||
sb.append("\t");
|
||||
sb.append("\n");
|
||||
sb.append("\r");
|
||||
sb.append("\f");
|
||||
sb.append("\b");
|
||||
sb.append("\013");
|
||||
sb.append('\'');
|
||||
sb.append('\\');
|
||||
sb.append('/');
|
||||
sb.append('\t');
|
||||
sb.append('\n');
|
||||
sb.append('\r');
|
||||
sb.append('\f');
|
||||
sb.append('\b');
|
||||
sb.append('\013');
|
||||
assertThat(JavaScriptUtils.javaScriptEscape(sb.toString())).isEqualTo("\\\"\\'\\\\\\/\\t\\n\\n\\f\\b\\v");
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -1210,7 +1210,7 @@ public class PathPatternTests {
|
||||
private String elementsToString(List<Element> elements) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (Element element: elements) {
|
||||
s.append("[").append(element.value()).append("]");
|
||||
s.append('[').append(element.value()).append(']');
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user