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>
|
<body>
|
||||||
|
|
||||||
<release version="3.5" date="tba" description="tba">
|
<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-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-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>
|
<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) {
|
public static String toFullyQualifiedName(final Package context, final String resourceName) {
|
||||||
Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
|
Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
|
||||||
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
|
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
|
||||||
final StringBuilder sb = new StringBuilder();
|
return context.getName() + "." + resourceName;
|
||||||
sb.append(context.getName());
|
|
||||||
sb.append(".");
|
|
||||||
sb.append(resourceName);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,11 +124,7 @@ public class ClassPathUtils {
|
||||||
public static String toFullyQualifiedPath(final Package context, final String resourceName) {
|
public static String toFullyQualifiedPath(final Package context, final String resourceName) {
|
||||||
Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
|
Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
|
||||||
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
|
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
|
||||||
final StringBuilder sb = new StringBuilder();
|
return context.getName().replace('.', '/') + "/" + resourceName;
|
||||||
sb.append(context.getName().replace('.', '/'));
|
|
||||||
sb.append("/");
|
|
||||||
sb.append(resourceName);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -445,18 +445,10 @@ public final class Range<T> implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String result = toString;
|
if (toString == null) {
|
||||||
if (result == null) {
|
toString = "[" + minimum + ".." + maximum + "]";
|
||||||
final StringBuilder buf = new StringBuilder(32);
|
|
||||||
buf.append('[');
|
|
||||||
buf.append(minimum);
|
|
||||||
buf.append("..");
|
|
||||||
buf.append(maximum);
|
|
||||||
buf.append(']');
|
|
||||||
result = buf.toString();
|
|
||||||
toString = result;
|
|
||||||
}
|
}
|
||||||
return result;
|
return toString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -897,7 +897,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (toString == null) {
|
if (toString == null) {
|
||||||
toString = new StringBuilder(32).append(getNumerator()).append('/').append(getDenominator()).toString();
|
toString = getNumerator() + "/" + getDenominator();
|
||||||
}
|
}
|
||||||
return toString;
|
return toString;
|
||||||
}
|
}
|
||||||
|
@ -928,12 +928,10 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
||||||
if (properNumerator == 0) {
|
if (properNumerator == 0) {
|
||||||
toProperString = Integer.toString(getProperWhole());
|
toProperString = Integer.toString(getProperWhole());
|
||||||
} else {
|
} else {
|
||||||
toProperString = new StringBuilder(32).append(getProperWhole()).append(' ').append(properNumerator)
|
toProperString = getProperWhole() + " " + properNumerator + "/" + getDenominator();
|
||||||
.append('/').append(getDenominator()).toString();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toProperString = new StringBuilder(32).append(getNumerator()).append('/').append(getDenominator())
|
toProperString = getNumerator() + "/" + getDenominator();
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return toProperString;
|
return toProperString;
|
||||||
|
|
|
@ -138,8 +138,7 @@ public abstract class Triple<L, M, R> implements Comparable<Triple<L, M, R>>, Se
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringBuilder().append('(').append(getLeft()).append(',').append(getMiddle()).append(',')
|
return "(" + getLeft() + "," + getMiddle() + "," + getRight() + ")";
|
||||||
.append(getRight()).append(')').toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -319,7 +319,7 @@ public class BooleanUtilsTest {
|
||||||
assertFalse(BooleanUtils.toBoolean("false"));
|
assertFalse(BooleanUtils.toBoolean("false"));
|
||||||
assertFalse(BooleanUtils.toBoolean("a"));
|
assertFalse(BooleanUtils.toBoolean("a"));
|
||||||
assertTrue(BooleanUtils.toBoolean("true")); // interned handled differently
|
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"));
|
assertTrue(BooleanUtils.toBoolean("trUe"));
|
||||||
assertTrue(BooleanUtils.toBoolean("trUE"));
|
assertTrue(BooleanUtils.toBoolean("trUE"));
|
||||||
|
|
|
@ -571,7 +571,7 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( "deprecation" ) // escapeXml(String) has been replaced by escapeXml10(String) and escapeXml11(String) in 3.3
|
@SuppressWarnings( "deprecation" ) // escapeXml(String) has been replaced by escapeXml10(String) and escapeXml11(String) in 3.3
|
||||||
public void testLang720() {
|
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);
|
final String escaped = StringEscapeUtils.escapeXml(input);
|
||||||
assertEquals(input, escaped);
|
assertEquals(input, escaped);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue