summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-12-17 21:09:08 -0800
committerElliott Hughes <enh@google.com>2009-12-18 10:35:28 -0800
commitf787a8787d0b7bcdc178ffc2e3343f1c1b02ed30 (patch)
tree2802ec85df008606d8e0765d8f3c14a090b12f93
parent2cb7451712f56b28daaf59c71831951b303c3dcf (diff)
downloadlibcore-f787a8787d0b7bcdc178ffc2e3343f1c1b02ed30.zip
libcore-f787a8787d0b7bcdc178ffc2e3343f1c1b02ed30.tar.gz
libcore-f787a8787d0b7bcdc178ffc2e3343f1c1b02ed30.tar.bz2
Depessimize string conversions.
Why does this idiom persist? It's ugly, and it's the least efficient way to do it. (I found the ones in DecimalFormatSymbols while invesigating why "new SimpleDateFormat()" burns through so many StringBuilders. grep(1) found the rest.) The DocumentBuilderImpl removes an unnecessary level of indirection, since we implement Character.toString in terms of String.valueOf. (I wouldn't have bothered except this was the only use of Character.toString in the core libraries, and I added it myself a few weeks ago.)
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java24
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/Resources.java4
-rw-r--r--luni/src/main/java/java/util/Date.java8
-rw-r--r--xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java2
4 files changed, 19 insertions, 19 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
index ebda335..533c674 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
@@ -125,23 +125,23 @@ public class DecimalFormatSymbols implements Cloneable {
public void setDecimalSeparator(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
- UNumberFormatSymbol.UNUM_DECIMAL_SEPARATOR_SYMBOL.ordinal(),
- "" + symbol);
+ UNumberFormatSymbol.UNUM_DECIMAL_SEPARATOR_SYMBOL.ordinal(),
+ String.valueOf(symbol));
}
public void setDigit(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_DIGIT_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setGroupingSeparator(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_GROUPING_SEPARATOR_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setInfinity(String symbol) {
@@ -159,43 +159,43 @@ public class DecimalFormatSymbols implements Cloneable {
public void setMinusSign(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_MINUS_SIGN_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setMonetaryDecimalSeparator(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_MONETARY_SEPARATOR_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setNaN(String symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_NAN_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setPatternSeparator(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_PATTERN_SEPARATOR_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setPercent(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_PERCENT_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setPerMill(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_PERMILL_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public void setZeroDigit(char symbol) {
NativeDecimalFormat.setSymbol(this.addr,
UNumberFormatSymbol.UNUM_ZERO_DIGIT_SYMBOL.ordinal(),
- "" + symbol);
+ String.valueOf(symbol));
}
public Currency getCurrency() {
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
index 086f8d4..7eeae7d 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
@@ -368,11 +368,11 @@ public class Resources {
return "-1";
}
int res = getFractionDigitsNative(key);
- if(res < 0) {
+ if (res < 0) {
throw new MissingResourceException("couldn't find resource.",
ISO4CurrenciesToDigits.class.getName(), key);
}
- return "" + res;
+ return Integer.toString(res);
}
}
diff --git a/luni/src/main/java/java/util/Date.java b/luni/src/main/java/java/util/Date.java
index 37f5b6a..3610847 100644
--- a/luni/src/main/java/java/util/Date.java
+++ b/luni/src/main/java/java/util/Date.java
@@ -714,11 +714,11 @@ public class Date implements Serializable, Cloneable, Comparable<Date> {
+ " " + cal.getTimeZone().getID() + " " + cal.get(Calendar.YEAR);//$NON-NLS-1$ //$NON-NLS-2$
}
- private String toTwoDigits(int digit) {
- if(digit >= 10) {
- return "" + digit;//$NON-NLS-1$
+ private String toTwoDigits(int n) {
+ if (n >= 10) {
+ return Integer.toString(n);//$NON-NLS-1$
} else {
- return "0" + digit;//$NON-NLS-1$
+ return "0" + n;//$NON-NLS-1$
}
}
diff --git a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java
index 1a8122c..eacf0a0 100644
--- a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java
+++ b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java
@@ -475,7 +475,7 @@ class DocumentBuilderImpl extends DocumentBuilder {
if (ch < 0 || ch > Character.MAX_VALUE) {
return null;
}
- return Character.toString((char) ch);
+ return String.valueOf((char) ch);
} catch (NumberFormatException ex) {
return null;
}