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.
diff --git a/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java b/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java
index 81c7578..df76385 100644
--- a/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java
+++ b/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java
@@ -69,7 +69,6 @@
     @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/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java b/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
index 7ae5f3f..2d5ae02 100644
--- a/libcore/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
+++ b/libcore/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 @@
 
 public class DecimalFormatSymbols implements Cloneable {
     
-    private final int addr;
-    
-    private final Locale loc;
+    // 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 DecimalFormatSymbols(int addr, Locale loc) {
-        this.addr = addr;
-        this.loc = loc;
+    private final int addr;
+
+    // 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 @@
      * 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 @@
 
     @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/libcore/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java b/libcore/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
index aa10efa..88e0d5f 100644
--- a/libcore/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
+++ b/libcore/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
@@ -21,28 +21,6 @@
 
 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, 
diff --git a/libcore/text/src/main/java/java/text/DecimalFormat.java b/libcore/text/src/main/java/java/text/DecimalFormat.java
index 7a85e71..3123e8c 100644
--- a/libcore/text/src/main/java/java/text/DecimalFormat.java
+++ b/libcore/text/src/main/java/java/text/DecimalFormat.java
@@ -625,6 +625,19 @@
         super.setMinimumIntegerDigits(dform.getMinimumIntegerDigits());
     }
 
+    // BEGIN android-added: used by NumberFormat.getInstance because cloning DecimalFormatSymbols is slow.
+    DecimalFormat(String pattern, Locale locale) {
+        this.symbols = new DecimalFormatSymbols(locale);
+        this.icuSymbols = new com.ibm.icu4jni.text.DecimalFormatSymbols(locale, symbols);
+        this.dform = new com.ibm.icu4jni.text.DecimalFormat(pattern, icuSymbols);
+
+        super.setMaximumFractionDigits(dform.getMaximumFractionDigits());
+        super.setMaximumIntegerDigits(dform.getMaximumIntegerDigits());
+        super.setMinimumFractionDigits(dform.getMinimumFractionDigits());
+        super.setMinimumIntegerDigits(dform.getMinimumIntegerDigits());
+    }
+    // END android-added
+
     // BEGIN android-removed
     // DecimalFormat(String pattern, DecimalFormatSymbols value, com.ibm.icu4jni.text.DecimalFormat icuFormat) {
     //     symbols = value;
diff --git a/libcore/text/src/main/java/java/text/NumberFormat.java b/libcore/text/src/main/java/java/text/NumberFormat.java
index ecf4483..5f6693d 100644
--- a/libcore/text/src/main/java/java/text/NumberFormat.java
+++ b/libcore/text/src/main/java/java/text/NumberFormat.java
@@ -358,7 +358,7 @@
     public static NumberFormat getCurrencyInstance(Locale locale) {
         // BEGIN android-changed
         LocaleData localeData = com.ibm.icu4jni.util.Resources.getLocaleData(locale);
-        return getInstance(locale, localeData.currencyPattern);
+        return getInstance(localeData.currencyPattern, locale);
         // END android-changed
     }
 
@@ -383,7 +383,7 @@
     public static NumberFormat getIntegerInstance(Locale locale) {
         // BEGIN android-changed
         LocaleData localeData = com.ibm.icu4jni.util.Resources.getLocaleData(locale);
-        NumberFormat result = getInstance(locale, localeData.integerPattern);
+        NumberFormat result = getInstance(localeData.integerPattern, locale);
         result.setParseIntegerOnly(true);
         return result;
         // END android-changed
@@ -412,8 +412,8 @@
     }
 
     // BEGIN android-added
-    private static NumberFormat getInstance(Locale locale, String pattern) {
-        return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
+    private static NumberFormat getInstance(String pattern, Locale locale) {
+        return new DecimalFormat(pattern, locale);
     }
     // END android-added
 
@@ -480,7 +480,7 @@
     public static NumberFormat getNumberInstance(Locale locale) {
         // BEGIN android-changed
         LocaleData localeData = com.ibm.icu4jni.util.Resources.getLocaleData(locale);
-        return getInstance(locale, localeData.numberPattern);
+        return getInstance(localeData.numberPattern, locale);
         // END android-changed
     }
 
@@ -505,7 +505,7 @@
     public static NumberFormat getPercentInstance(Locale locale) {
         // BEGIN android-changed
         LocaleData localeData = com.ibm.icu4jni.util.Resources.getLocaleData(locale);
-        return getInstance(locale, localeData.percentPattern);
+        return getInstance(localeData.percentPattern, locale);
         // END android-changed
     }