LANG-1057
Micro optimization: Replace StringBuilder with String concatenation so that the compiler can better optimize the code
This commit is contained in:
parent
fb7784fa14
commit
cc1aed9bdf
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.5" date="tba" description="tba">
|
||||
<action issue="LANG-1057" type="update" dev="chas" dute-to="Otávio Santana">Replace StringBuilder with String concatenation for better optimization</action>
|
||||
<action issue="LANG-1075" type="update" dev="chas">Deprecate SystemUtils.FILE_SEPARATOR and SystemUtils.PATH_SEPARATOR</action>
|
||||
<action issue="LANG-1154" type="add" dev="chas" due-to="Gary Gregory">FastDateFormat APIs that use a StringBuilder</action>
|
||||
<action issue="LANG-1149" type="add" dev="chas" due-to="Gregory Zak">Ability to throw checked exceptions without declaring them</action>
|
||||
|
|
|
@ -79,11 +79,7 @@ public class ClassPathUtils {
|
|||
public static String toFullyQualifiedName(final Package context, final String resourceName) {
|
||||
Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
|
||||
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(context.getName());
|
||||
sb.append(".");
|
||||
sb.append(resourceName);
|
||||
return sb.toString();
|
||||
return context.getName() + "." + resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,11 +124,7 @@ public class ClassPathUtils {
|
|||
public static String toFullyQualifiedPath(final Package context, final String resourceName) {
|
||||
Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
|
||||
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(context.getName().replace('.', '/'));
|
||||
sb.append("/");
|
||||
sb.append(resourceName);
|
||||
return sb.toString();
|
||||
return context.getName().replace('.', '/') + "/" + resourceName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -445,18 +445,10 @@ public final class Range<T> implements Serializable {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = toString;
|
||||
if (result == null) {
|
||||
final StringBuilder buf = new StringBuilder(32);
|
||||
buf.append('[');
|
||||
buf.append(minimum);
|
||||
buf.append("..");
|
||||
buf.append(maximum);
|
||||
buf.append(']');
|
||||
result = buf.toString();
|
||||
toString = result;
|
||||
if (toString == null) {
|
||||
toString = "[" + minimum + ".." + maximum + "]";
|
||||
}
|
||||
return result;
|
||||
return toString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -897,7 +897,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
@Override
|
||||
public String toString() {
|
||||
if (toString == null) {
|
||||
toString = new StringBuilder(32).append(getNumerator()).append('/').append(getDenominator()).toString();
|
||||
toString = getNumerator() + "/" + getDenominator();
|
||||
}
|
||||
return toString;
|
||||
}
|
||||
|
@ -928,12 +928,10 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
if (properNumerator == 0) {
|
||||
toProperString = Integer.toString(getProperWhole());
|
||||
} else {
|
||||
toProperString = new StringBuilder(32).append(getProperWhole()).append(' ').append(properNumerator)
|
||||
.append('/').append(getDenominator()).toString();
|
||||
toProperString = getProperWhole() + " " + properNumerator + "/" + getDenominator();
|
||||
}
|
||||
} else {
|
||||
toProperString = new StringBuilder(32).append(getNumerator()).append('/').append(getDenominator())
|
||||
.toString();
|
||||
toProperString = getNumerator() + "/" + getDenominator();
|
||||
}
|
||||
}
|
||||
return toProperString;
|
||||
|
|
|
@ -138,8 +138,7 @@ public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Se
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder().append('(').append(getLeft()).append(',').append(getMiddle()).append(',')
|
||||
.append(getRight()).append(')').toString();
|
||||
return "(" + getLeft() + "," + getMiddle() + "," + getRight() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -319,7 +319,7 @@ public class BooleanUtilsTest {
|
|||
assertFalse(BooleanUtils.toBoolean("false"));
|
||||
assertFalse(BooleanUtils.toBoolean("a"));
|
||||
assertTrue(BooleanUtils.toBoolean("true")); // interned handled differently
|
||||
assertTrue(BooleanUtils.toBoolean(new StringBuffer("tr").append("ue").toString()));
|
||||
assertTrue(BooleanUtils.toBoolean(new StringBuilder("tr").append("ue").toString()));
|
||||
assertTrue(BooleanUtils.toBoolean("truE"));
|
||||
assertTrue(BooleanUtils.toBoolean("trUe"));
|
||||
assertTrue(BooleanUtils.toBoolean("trUE"));
|
||||
|
|
|
@ -571,7 +571,7 @@ public class StringEscapeUtilsTest {
|
|||
@Test
|
||||
@SuppressWarnings( "deprecation" ) // escapeXml(String) has been replaced by escapeXml10(String) and escapeXml11(String) in 3.3
|
||||
public void testLang720() {
|
||||
final String input = new StringBuilder("\ud842\udfb7").append("A").toString();
|
||||
final String input = "\ud842\udfb7" + "A";
|
||||
final String escaped = StringEscapeUtils.escapeXml(input);
|
||||
assertEquals(input, escaped);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue