diff options
author | Elliott Hughes <enh@google.com> | 2010-01-05 11:24:56 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-01-05 13:54:14 -0800 |
commit | a05602fd81ff398fd6381390a0886608fec5f95c (patch) | |
tree | 3b3a73611b3fc3dfe9b8bdfb2d5ca7af32252d0b /icu | |
parent | e626054a49de4d92623267e88239d6f0a4049d6f (diff) | |
download | libcore-a05602fd81ff398fd6381390a0886608fec5f95c.zip libcore-a05602fd81ff398fd6381390a0886608fec5f95c.tar.gz libcore-a05602fd81ff398fd6381390a0886608fec5f95c.tar.bz2 |
Last bunch of NumberFormat speedups.
Don't mess around with setCurrency in DecimalFormat.copySymbols when we're
going to override any effect that call will have had in the next few lines:
we always call setCurrencySymbol and setInternationalCurrencySymbol, so
setCurrency is just wasting time.
Replaces the NativeDecimalFormat.UNumberFormatSymbol enum -- which was only used
for getting ints to pass to native code, using Enum.ordinal -- with ints.
Adds a constructor to the java.text DecimalFormat so we can avoid cloning the
DecimalFormatSymbols object we create for its private use.
This is another 10% shaved off.
I've also removed an unused local from the icu4jni DecimalFormat, so I can
remove a then-unused getLocale method from the ICU DecimalFormatSymbols.
I've rewritten the icu4jni DecimalFormatSymbols.clone to remove the scary
constructor that took an arbitrary int and treated it as a uintptr_t when
talking to native code.
Diffstat (limited to 'icu')
3 files changed, 60 insertions, 123 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java index 81c7578..df76385 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java @@ -69,7 +69,6 @@ public class DecimalFormat extends NumberFormat { @Override public Object clone() { String pat = this.toPattern(); - Locale loc = this.symbols.getLocale(); DecimalFormatSymbols sym = (DecimalFormatSymbols) this.symbols.clone(); DecimalFormat newdf = new DecimalFormat(pat, sym); newdf.setMaximumIntegerDigits(this.getMaximumIntegerDigits()); 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 7ae5f3f..2d5ae02 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java @@ -16,7 +16,6 @@ package com.ibm.icu4jni.text; -import com.ibm.icu4jni.text.NativeDecimalFormat.UNumberFormatSymbol; import com.ibm.icu4jni.util.LocaleData; import java.security.AccessController; @@ -27,30 +26,45 @@ import java.util.ResourceBundle; public class DecimalFormatSymbols implements Cloneable { + // Constants corresponding to the native type UNumberFormatSymbol, for use with getSymbol/setSymbol. + private static final int UNUM_DECIMAL_SEPARATOR_SYMBOL = 0; + private static final int UNUM_GROUPING_SEPARATOR_SYMBOL = 1; + private static final int UNUM_PATTERN_SEPARATOR_SYMBOL = 2; + private static final int UNUM_PERCENT_SYMBOL = 3; + private static final int UNUM_ZERO_DIGIT_SYMBOL = 4; + private static final int UNUM_DIGIT_SYMBOL = 5; + private static final int UNUM_MINUS_SIGN_SYMBOL = 6; + private static final int UNUM_PLUS_SIGN_SYMBOL = 7; + private static final int UNUM_CURRENCY_SYMBOL = 8; + private static final int UNUM_INTL_CURRENCY_SYMBOL = 9; + private static final int UNUM_MONETARY_SEPARATOR_SYMBOL = 10; + private static final int UNUM_EXPONENTIAL_SYMBOL = 11; + private static final int UNUM_PERMILL_SYMBOL = 12; + private static final int UNUM_PAD_ESCAPE_SYMBOL = 13; + private static final int UNUM_INFINITY_SYMBOL = 14; + private static final int UNUM_NAN_SYMBOL = 15; + private static final int UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16; + private static final int UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17; + private static final int UNUM_FORMAT_SYMBOL_COUNT = 18; + private final int addr; - - private final Locale loc; - private DecimalFormatSymbols(int addr, Locale loc) { - this.addr = addr; - this.loc = loc; + // Used to implement clone. + private DecimalFormatSymbols(DecimalFormatSymbols other) { + this.addr = NativeDecimalFormat.cloneImpl(other.addr); } public DecimalFormatSymbols(Locale locale) { LocaleData localeData = com.ibm.icu4jni.util.Resources.getLocaleData(locale); - this.loc = locale; this.addr = NativeDecimalFormat.openDecimalFormatImpl(locale.toString(), localeData.numberPattern); - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_CURRENCY_SYMBOL.ordinal(), localeData.currencySymbol); - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), + NativeDecimalFormat.setSymbol(this.addr, UNUM_CURRENCY_SYMBOL, localeData.currencySymbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL, 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); @@ -60,13 +74,6 @@ public class DecimalFormatSymbols implements Cloneable { * 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()); @@ -129,179 +136,132 @@ public class DecimalFormatSymbols implements Cloneable { @Override public Object clone() { - int addr = NativeDecimalFormat.cloneImpl(this.addr); - Locale loc = (Locale) this.loc.clone(); - return new DecimalFormatSymbols(addr, loc); + return new DecimalFormatSymbols(this); } public void setCurrency(Currency currency) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_CURRENCY_SYMBOL.ordinal(), - currency.getSymbol()); - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), - currency.getCurrencyCode()); + NativeDecimalFormat.setSymbol(this.addr, UNUM_CURRENCY_SYMBOL, currency.getSymbol()); + NativeDecimalFormat.setSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL, + currency.getCurrencyCode()); } public void setCurrencySymbol(String symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_CURRENCY_SYMBOL.ordinal(), - symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_CURRENCY_SYMBOL, symbol); } public void setDecimalSeparator(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_DECIMAL_SEPARATOR_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_DECIMAL_SEPARATOR_SYMBOL, symbol); } public void setDigit(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_DIGIT_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_DIGIT_SYMBOL, symbol); } public void setGroupingSeparator(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_GROUPING_SEPARATOR_SYMBOL.ordinal(), symbol); - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_GROUPING_SEPARATOR_SYMBOL, symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, symbol); } public void setInfinity(String symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INFINITY_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_INFINITY_SYMBOL, symbol); } public void setInternationalCurrencySymbol(String symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL, symbol); } public void setMinusSign(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_MINUS_SIGN_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_MINUS_SIGN_SYMBOL, symbol); } public void setMonetaryDecimalSeparator(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_MONETARY_SEPARATOR_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_MONETARY_SEPARATOR_SYMBOL, symbol); } public void setNaN(String symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_NAN_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_NAN_SYMBOL, symbol); } public void setPatternSeparator(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_PATTERN_SEPARATOR_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_PATTERN_SEPARATOR_SYMBOL, symbol); } public void setPercent(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_PERCENT_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_PERCENT_SYMBOL, symbol); } public void setPerMill(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_PERMILL_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_PERMILL_SYMBOL, symbol); } public void setZeroDigit(char symbol) { - NativeDecimalFormat.setSymbol(this.addr, - UNumberFormatSymbol.UNUM_ZERO_DIGIT_SYMBOL.ordinal(), symbol); + NativeDecimalFormat.setSymbol(this.addr, UNUM_ZERO_DIGIT_SYMBOL, symbol); } public Currency getCurrency() { - String curr = NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal()); - if(curr.equals("") || curr.equals("\u00a4\u00a4")) { + String curr = NativeDecimalFormat.getSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL); + if (curr.equals("") || curr.equals("\u00a4\u00a4")) { return null; } - return Currency.getInstance(curr); + return Currency.getInstance(curr); } public String getCurrencySymbol() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_CURRENCY_SYMBOL.ordinal()); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_CURRENCY_SYMBOL); } public char getDecimalSeparator() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_DECIMAL_SEPARATOR_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_DECIMAL_SEPARATOR_SYMBOL).charAt(0); } public char getDigit() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_DIGIT_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_DIGIT_SYMBOL).charAt(0); } public char getGroupingSeparator() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_GROUPING_SEPARATOR_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_GROUPING_SEPARATOR_SYMBOL).charAt(0); } public String getInfinity() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_INFINITY_SYMBOL.ordinal()); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_INFINITY_SYMBOL); } public String getInternationalCurrencySymbol() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_INTL_CURRENCY_SYMBOL.ordinal()); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL); } public char getMinusSign() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_MINUS_SIGN_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_MINUS_SIGN_SYMBOL).charAt(0); } public char getMonetaryDecimalSeparator() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_MONETARY_SEPARATOR_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_MONETARY_SEPARATOR_SYMBOL).charAt(0); } public String getNaN() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_NAN_SYMBOL.ordinal()); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_NAN_SYMBOL); } public char getPatternSeparator() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_PATTERN_SEPARATOR_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_PATTERN_SEPARATOR_SYMBOL).charAt(0); } public char getPercent() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_PERCENT_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_PERCENT_SYMBOL).charAt(0); } public char getPerMill() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_PERMILL_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_PERMILL_SYMBOL).charAt(0); } public char getZeroDigit() { - return NativeDecimalFormat.getSymbol(this.addr, - UNumberFormatSymbol.UNUM_ZERO_DIGIT_SYMBOL.ordinal()) - .charAt(0); + return NativeDecimalFormat.getSymbol(this.addr, UNUM_ZERO_DIGIT_SYMBOL).charAt(0); } int getAddr() { return this.addr; } - Locale getLocale() { - return this.loc; - } - protected void finalize() { NativeDecimalFormat.closeDecimalFormatImpl(this.addr); } 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 aa10efa..88e0d5f 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java @@ -21,28 +21,6 @@ import java.text.ParsePosition; final class NativeDecimalFormat { - enum UNumberFormatSymbol { - UNUM_DECIMAL_SEPARATOR_SYMBOL, - UNUM_GROUPING_SEPARATOR_SYMBOL, - UNUM_PATTERN_SEPARATOR_SYMBOL, - UNUM_PERCENT_SYMBOL, - UNUM_ZERO_DIGIT_SYMBOL, - UNUM_DIGIT_SYMBOL, - UNUM_MINUS_SIGN_SYMBOL, - UNUM_PLUS_SIGN_SYMBOL, - UNUM_CURRENCY_SYMBOL, - UNUM_INTL_CURRENCY_SYMBOL, - UNUM_MONETARY_SEPARATOR_SYMBOL, - UNUM_EXPONENTIAL_SYMBOL, - UNUM_PERMILL_SYMBOL, - UNUM_PAD_ESCAPE_SYMBOL, - UNUM_INFINITY_SYMBOL, - UNUM_NAN_SYMBOL, - UNUM_SIGNIFICANT_DIGIT_SYMBOL, - UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, - UNUM_FORMAT_SYMBOL_COUNT - } - enum UNumberFormatAttribute { UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, |