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-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.
|
||||
@@ -70,7 +70,7 @@ public class MethodArgumentNotValidException extends MethodArgumentResolutionExc
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(bindingResult.getErrorCount()).append(" error(s): ");
|
||||
for (ObjectError error : 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.
|
||||
@@ -208,7 +208,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor {
|
||||
}
|
||||
StringBuilder sb = getBaseLogMessage();
|
||||
if (!CollectionUtils.isEmpty(getSessionAttributes())) {
|
||||
sb.append(" attributes[").append(getSessionAttributes().size()).append("]");
|
||||
sb.append(" attributes[").append(getSessionAttributes().size()).append(']');
|
||||
}
|
||||
sb.append(getShortPayloadLogMessage(payload));
|
||||
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.
|
||||
@@ -452,7 +452,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||
return super.getDetailedLogMessage(payload);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(command.name()).append(" ");
|
||||
sb.append(command.name()).append(' ');
|
||||
Map<String, List<String>> nativeHeaders = getNativeHeaders();
|
||||
if (nativeHeaders != null) {
|
||||
sb.append(nativeHeaders);
|
||||
|
||||
@@ -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.
|
||||
@@ -112,12 +112,12 @@ public class GenericMessage<T> implements Message<T>, Serializable {
|
||||
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
|
||||
sb.append(" [payload=");
|
||||
if (this.payload instanceof byte[]) {
|
||||
sb.append("byte[").append(((byte[]) this.payload).length).append("]");
|
||||
sb.append("byte[").append(((byte[]) this.payload).length).append(']');
|
||||
}
|
||||
else {
|
||||
sb.append(this.payload);
|
||||
}
|
||||
sb.append(", headers=").append(this.headers).append("]");
|
||||
sb.append(", headers=").append(this.headers).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.
|
||||
@@ -241,7 +241,7 @@ public class StompHeaderAccessorTests {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 80; i++) {
|
||||
sb.append("a");
|
||||
sb.append('a');
|
||||
}
|
||||
final String payload = sb.toString() + " > 80";
|
||||
actual = accessor.getShortLogMessage(payload.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
@@ -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.
|
||||
@@ -320,7 +320,7 @@ public class MessageHeaderAccessorTests {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 80; i++) {
|
||||
sb.append("a");
|
||||
sb.append('a');
|
||||
}
|
||||
final String payload = sb.toString() + " > 80";
|
||||
|
||||
@@ -356,7 +356,7 @@ public class MessageHeaderAccessorTests {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 80; i++) {
|
||||
sb.append("a");
|
||||
sb.append('a');
|
||||
}
|
||||
final String payload = sb.toString() + " > 80";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user