summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-01-28 12:18:39 -0800
committerElliott Hughes <enh@google.com>2010-01-28 12:18:39 -0800
commitd5344fec27edfcf7acf9f703c9d7dff14a832943 (patch)
tree4230a4bb322859e5c55eab2bec42cfa4934d9e8b /icu/src/main/java
parenta747155a09a9ade533379872e292a74329581292 (diff)
downloadlibcore-d5344fec27edfcf7acf9f703c9d7dff14a832943.zip
libcore-d5344fec27edfcf7acf9f703c9d7dff14a832943.tar.gz
libcore-d5344fec27edfcf7acf9f703c9d7dff14a832943.tar.bz2
Double the speed of DecimalFormat creation.
Our calls to unum_setSymbol were making us O(n^2); switching to the C++ API and doing a bulk update is a huge win. (ICU is really a C++ library with a C wrapper. It's always going to be slightly wasteful to go via C, but here it's especially harmful.) The new ScopedJavaUnicodeString provides a best-of-breed bridge between Java strings on the Java heap and the UnicodeString type that ICU wants. I'll come back and switch more of our ICU JNI over in a later patch.
Diffstat (limited to 'icu/src/main/java')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java37
1 files changed, 14 insertions, 23 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
index 034491c..7cb5de2 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
@@ -118,7 +118,7 @@ public class NativeDecimalFormat {
private BigDecimal multiplierBigDecimal = null;
public NativeDecimalFormat(String pattern, Locale locale, DecimalFormatSymbols symbols) {
- this.addr = openDecimalFormat(locale.toString(), pattern);
+ this.addr = openDecimalFormat(pattern);
this.lastPattern = pattern;
setDecimalFormatSymbols(symbols);
}
@@ -188,27 +188,14 @@ public class NativeDecimalFormat {
}
/**
- * Copies the DecimalFormatSymbols settings into our native peer.
+ * Copies the DecimalFormatSymbols settings into our native peer in bulk.
*/
public void setDecimalFormatSymbols(final DecimalFormatSymbols dfs) {
- setSymbol(this.addr, UNUM_CURRENCY_SYMBOL, dfs.getCurrencySymbol());
-
- setSymbol(this.addr, UNUM_DECIMAL_SEPARATOR_SYMBOL, dfs.getDecimalSeparator());
- setSymbol(this.addr, UNUM_DIGIT_SYMBOL, dfs.getDigit());
-
- char groupingSeparator = dfs.getGroupingSeparator();
- setSymbol(this.addr, UNUM_GROUPING_SEPARATOR_SYMBOL, groupingSeparator);
- setSymbol(this.addr, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, groupingSeparator);
-
- setSymbol(this.addr, UNUM_INFINITY_SYMBOL, dfs.getInfinity());
- setSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL, dfs.getInternationalCurrencySymbol());
- setSymbol(this.addr, UNUM_MINUS_SIGN_SYMBOL, dfs.getMinusSign());
- setSymbol(this.addr, UNUM_MONETARY_SEPARATOR_SYMBOL, dfs.getMonetaryDecimalSeparator());
- setSymbol(this.addr, UNUM_NAN_SYMBOL, dfs.getNaN());
- setSymbol(this.addr, UNUM_PATTERN_SEPARATOR_SYMBOL, dfs.getPatternSeparator());
- setSymbol(this.addr, UNUM_PERCENT_SYMBOL, dfs.getPercent());
- setSymbol(this.addr, UNUM_PERMILL_SYMBOL, dfs.getPerMill());
- setSymbol(this.addr, UNUM_ZERO_DIGIT_SYMBOL, dfs.getZeroDigit());
+ setDecimalFormatSymbols(this.addr, dfs.getCurrencySymbol(), dfs.getDecimalSeparator(),
+ dfs.getDigit(), dfs.getGroupingSeparator(), dfs.getInfinity(),
+ dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
+ dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
+ dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
}
private BigDecimal applyMultiplier(BigDecimal valBigDecimal) {
@@ -573,10 +560,10 @@ public class NativeDecimalFormat {
return null;
}
- private static int openDecimalFormat(String locale, String pattern) {
+ private static int openDecimalFormat(String pattern) {
try {
// FIXME: if we're about to override everything, should we just ask for the cheapest locale (presumably the root locale)?
- return openDecimalFormatImpl(locale, pattern);
+ return openDecimalFormatImpl(pattern);
} catch (NullPointerException npe) {
throw npe;
} catch (RuntimeException re) {
@@ -604,8 +591,12 @@ public class NativeDecimalFormat {
// FIXME: do we need getSymbol any more? the Java-side object should be the canonical source.
private static native String getSymbol(int addr, int symbol);
private static native String getTextAttribute(int addr, int symbol);
- private static native int openDecimalFormatImpl(String locale, String pattern);
+ private static native int openDecimalFormatImpl(String pattern);
private static native Number parse(int addr, String string, ParsePosition position);
+ private static native void setDecimalFormatSymbols(int addr, String currencySymbol,
+ char decimalSeparator, char digit, char groupingSeparator, String infinity,
+ String internationalCurrencySymbol, char minusSign, char monetaryDecimalSeparator,
+ String nan, char patternSeparator, char percent, char perMill, char zeroDigit);
private static native void setSymbol(int addr, int symbol, String str);
private static native void setSymbol(int addr, int symbol, char ch);
private static native void setAttribute(int addr, int symbol, int i);