diff options
author | Elliott Hughes <enh@google.com> | 2010-01-04 15:23:25 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-01-04 16:20:43 -0800 |
commit | 64e410fa8b4771a8749f899134b4e08c2fd49e3c (patch) | |
tree | 658fd2e49b5a0887072958d8f83a9f7d5a156c2c /icu/src/main/java | |
parent | 6ca85c49efc0f02d69933f60b207b964a999061f (diff) | |
download | libcore-64e410fa8b4771a8749f899134b4e08c2fd49e3c.zip libcore-64e410fa8b4771a8749f899134b4e08c2fd49e3c.tar.gz libcore-64e410fa8b4771a8749f899134b4e08c2fd49e3c.tar.bz2 |
Speed up DecimalFormatSymbols.
We don't need to create temporary String objects; we can just pass a char
directly. We also don't need to initialize aspects of our native peer if
we know we're going to overwrite them straight away, and making copying
into ICU the responsibility of the icu4jni class rather than the java.text
is slightly cleaner.
Together, these changes make creating a new NumberFormat about 20% faster.
Diffstat (limited to 'icu/src/main/java')
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java | 79 | ||||
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java | 1 |
2 files changed, 51 insertions, 29 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 43ac3f2..7ae5f3f 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java @@ -27,9 +27,9 @@ import java.util.ResourceBundle; public class DecimalFormatSymbols implements Cloneable { - private int addr; + private final int addr; - private Locale loc; + private final Locale loc; private DecimalFormatSymbols(int addr, Locale loc) { this.addr = addr; @@ -44,10 +44,44 @@ public class DecimalFormatSymbols implements Cloneable { NativeDecimalFormat.setSymbol(this.addr, UNumberFormatSymbol.UNUM_CURRENCY_SYMBOL.ordinal(), localeData.currencySymbol); NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), + UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), localeData.internationalCurrencySymbol); } + public DecimalFormatSymbols(Locale locale, java.text.DecimalFormatSymbols symbols) { + LocaleData localeData = com.ibm.icu4jni.util.Resources.getLocaleData(locale); + this.loc = locale; + this.addr = NativeDecimalFormat.openDecimalFormatImpl(locale.toString(), + localeData.numberPattern); + copySymbols(symbols); + } + + /** + * Copies the java.text.DecimalFormatSymbols' settings into this object. + */ + public void copySymbols(final java.text.DecimalFormatSymbols dfs) { + Currency currency = dfs.getCurrency(); + if (currency == null) { + setCurrency(Currency.getInstance("XXX")); //$NON-NLS-1$ + } else { + setCurrency(Currency.getInstance(currency.getCurrencyCode())); + } + + setCurrencySymbol(dfs.getCurrencySymbol()); + setDecimalSeparator(dfs.getDecimalSeparator()); + setDigit(dfs.getDigit()); + setGroupingSeparator(dfs.getGroupingSeparator()); + setInfinity(dfs.getInfinity()); + setInternationalCurrencySymbol(dfs.getInternationalCurrencySymbol()); + setMinusSign(dfs.getMinusSign()); + setMonetaryDecimalSeparator(dfs.getMonetaryDecimalSeparator()); + setNaN(dfs.getNaN()); + setPatternSeparator(dfs.getPatternSeparator()); + setPercent(dfs.getPercent()); + setPerMill(dfs.getPerMill()); + setZeroDigit(dfs.getZeroDigit()); + } + @Override public boolean equals(Object object) { if(object == null) { @@ -117,77 +151,64 @@ public class DecimalFormatSymbols implements Cloneable { public void setDecimalSeparator(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_DECIMAL_SEPARATOR_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_DECIMAL_SEPARATOR_SYMBOL.ordinal(), symbol); } public void setDigit(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_DIGIT_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_DIGIT_SYMBOL.ordinal(), symbol); } public void setGroupingSeparator(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_GROUPING_SEPARATOR_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_GROUPING_SEPARATOR_SYMBOL.ordinal(), symbol); NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL.ordinal(), symbol); } public void setInfinity(String symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INFINITY_SYMBOL.ordinal(), - symbol); + UNumberFormatSymbol.UNUM_INFINITY_SYMBOL.ordinal(), symbol); } public void setInternationalCurrencySymbol(String symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), - symbol); + UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), symbol); } public void setMinusSign(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_MINUS_SIGN_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_MINUS_SIGN_SYMBOL.ordinal(), symbol); } public void setMonetaryDecimalSeparator(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_MONETARY_SEPARATOR_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_MONETARY_SEPARATOR_SYMBOL.ordinal(), symbol); } public void setNaN(String symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_NAN_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_NAN_SYMBOL.ordinal(), symbol); } public void setPatternSeparator(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_PATTERN_SEPARATOR_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_PATTERN_SEPARATOR_SYMBOL.ordinal(), symbol); } public void setPercent(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_PERCENT_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_PERCENT_SYMBOL.ordinal(), symbol); } public void setPerMill(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_PERMILL_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_PERMILL_SYMBOL.ordinal(), symbol); } public void setZeroDigit(char symbol) { NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_ZERO_DIGIT_SYMBOL.ordinal(), - String.valueOf(symbol)); + UNumberFormatSymbol.UNUM_ZERO_DIGIT_SYMBOL.ordinal(), symbol); } public Currency getCurrency() { 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 39f7307..aa10efa 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java @@ -84,6 +84,7 @@ final class NativeDecimalFormat { static native int cloneImpl(int addr); static native void setSymbol(int addr, int symbol, String str); + static native void setSymbol(int addr, int symbol, char ch); static native String getSymbol(int addr, int symbol); |