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:
Sam Brannen
2021-06-24 18:53:51 +02:00
parent ddbb7c1b5b
commit a2ef6badc4
74 changed files with 232 additions and 220 deletions

View File

@@ -245,22 +245,22 @@ public abstract class AbstractExpressionTests {
sb.append("int[").append(l.length).append("]{");
for (int j = 0; j < l.length; j++) {
if (j > 0) {
sb.append(",");
sb.append(',');
}
sb.append(stringValueOf(l[j]));
}
sb.append("}");
sb.append('}');
}
else if (primitiveType == Long.TYPE) {
long[] l = (long[]) value;
sb.append("long[").append(l.length).append("]{");
for (int j = 0; j < l.length; j++) {
if (j > 0) {
sb.append(",");
sb.append(',');
}
sb.append(stringValueOf(l[j]));
}
sb.append("}");
sb.append('}');
}
else {
throw new RuntimeException("Please implement support for type " + primitiveType.getName() +
@@ -272,32 +272,32 @@ public abstract class AbstractExpressionTests {
if (!isNested) {
sb.append(value.getClass().getComponentType().getName());
}
sb.append("[").append(l.size()).append("]{");
sb.append('[').append(l.size()).append("]{");
int i = 0;
for (Object object : l) {
if (i > 0) {
sb.append(",");
sb.append(',');
}
i++;
sb.append(stringValueOf(object, true));
}
sb.append("}");
sb.append('}');
}
else {
List<Object> l = Arrays.asList((Object[]) value);
if (!isNested) {
sb.append(value.getClass().getComponentType().getName());
}
sb.append("[").append(l.size()).append("]{");
sb.append('[').append(l.size()).append("]{");
int i = 0;
for (Object object : l) {
if (i > 0) {
sb.append(",");
sb.append(',');
}
i++;
sb.append(stringValueOf(object));
}
sb.append("}");
sb.append('}');
}
return sb.toString();
}

View File

@@ -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.
@@ -5111,21 +5111,21 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
List<?> ls = (List<?>) object;
for (Object l: ls) {
s.append(l);
s.append(" ");
s.append(' ');
}
}
else if (object instanceof Object[]) {
Object[] os = (Object[]) object;
for (Object o: os) {
s.append(o);
s.append(" ");
s.append(' ');
}
}
else if (object instanceof int[]) {
int[] is = (int[]) object;
for (int i: is) {
s.append(i);
s.append(" ");
s.append(' ');
}
}
else {
@@ -5931,9 +5931,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
public Obj3(String s, Float f, int... ints) {
StringBuilder b = new StringBuilder();
b.append(s);
b.append(":");
b.append(':');
b.append(Float.toString(f));
b.append(":");
b.append(':');
for (int param: ints) {
b.append(Integer.toString(param));
}