summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-01-28 17:47:00 -0800
committerElliott Hughes <enh@google.com>2010-01-28 17:47:00 -0800
commit5d593ea1361bd7c5ef3353b66d63ac64e95d9d41 (patch)
treea1212d037a0540cd8d05cf925cfb5ddd93cfe8df /icu/src/main/java
parentbe815a27c0dc051faf5a9642a5387f091f519efa (diff)
downloadlibcore-5d593ea1361bd7c5ef3353b66d63ac64e95d9d41.zip
libcore-5d593ea1361bd7c5ef3353b66d63ac64e95d9d41.tar.gz
libcore-5d593ea1361bd7c5ef3353b66d63ac64e95d9d41.tar.bz2
Use DecimalFormatSymbols' new default constructor for speed.
This brings "new DecimalFormat" down to ~80us (from ~260us before this patch, or ~600us this time last week). Also remove some dead code and tighten up some accessibility. Depends on https://android-git.corp.google.com/g/38877.
Diffstat (limited to 'icu/src/main/java')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java49
1 files changed, 19 insertions, 30 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 7cb5de2..d1da72f 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
@@ -32,7 +32,7 @@ import java.util.Locale;
public class NativeDecimalFormat {
/**
- * Constants corresponding to the native type UNumberFormatSymbol, for getSymbol/setSymbol.
+ * Constants corresponding to the native type UNumberFormatSymbol, for setSymbol.
*/
private static final int UNUM_DECIMAL_SEPARATOR_SYMBOL = 0;
private static final int UNUM_GROUPING_SEPARATOR_SYMBOL = 1;
@@ -117,10 +117,19 @@ public class NativeDecimalFormat {
*/
private BigDecimal multiplierBigDecimal = null;
- public NativeDecimalFormat(String pattern, Locale locale, DecimalFormatSymbols symbols) {
- this.addr = openDecimalFormat(pattern);
- this.lastPattern = pattern;
- setDecimalFormatSymbols(symbols);
+ public NativeDecimalFormat(String pattern, DecimalFormatSymbols dfs) {
+ try {
+ this.addr = openDecimalFormatImpl(pattern, 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());
+ this.lastPattern = pattern;
+ } catch (NullPointerException npe) {
+ throw npe;
+ } catch (RuntimeException re) {
+ throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
+ }
}
// Used to implement clone.
@@ -183,8 +192,7 @@ public class NativeDecimalFormat {
obj.getMaximumFractionDigits() == this.getMaximumFractionDigits() &&
obj.getMinimumIntegerDigits() == this.getMinimumIntegerDigits() &&
obj.getMinimumFractionDigits() == this.getMinimumFractionDigits() &&
- obj.isGroupingUsed() == this.isGroupingUsed() &&
- obj.getCurrency() == this.getCurrency();
+ obj.isGroupingUsed() == this.isGroupingUsed();
}
/**
@@ -350,14 +358,6 @@ public class NativeDecimalFormat {
return getAttribute(this.addr, UNUM_MIN_INTEGER_DIGITS);
}
- public Currency getCurrency() {
- String curr = getSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL);
- if (curr.equals("") || curr.equals("\u00a4\u00a4")) {
- return null;
- }
- return Currency.getInstance(curr);
- }
-
public int getGroupingSize() {
return getAttribute(this.addr, UNUM_GROUPING_SIZE);
}
@@ -560,17 +560,6 @@ public class NativeDecimalFormat {
return null;
}
- 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(pattern);
- } catch (NullPointerException npe) {
- throw npe;
- } catch (RuntimeException re) {
- throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
- }
- }
-
private static void applyPattern(int addr, boolean localized, String pattern) {
try {
applyPatternImpl(addr, localized, pattern);
@@ -588,17 +577,17 @@ public class NativeDecimalFormat {
private static native String format(int addr, double value, FieldPosition position, String fieldType, StringBuffer attributes);
private static native String format(int addr, String value, FieldPosition position, String fieldType, StringBuffer attributes, int scale);
private static native int getAttribute(int addr, int symbol);
- // 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 pattern);
+ private static native int openDecimalFormatImpl(String pattern, 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 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);
private static native void setTextAttribute(int addr, int symbol, String str);
private static native String toPatternImpl(int addr, boolean localized);