changeset 7450:ffd8b8da0696

7156459: Remove unnecessary get() from Currency.getInstance() Reviewed-by: chegar, dholmes, mduigou
author naoto
date Tue, 27 Mar 2012 10:10:47 -0700
parents 43db70cf8b20
children e5831ecc079b
files src/share/classes/java/util/Currency.java
diffstat 1 files changed, 35 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Currency.java	Wed Mar 21 10:10:38 2012 -0700
+++ b/src/share/classes/java/util/Currency.java	Tue Mar 27 10:10:47 2012 -0700
@@ -288,46 +288,47 @@
 
     private static Currency getInstance(String currencyCode, int defaultFractionDigits,
         int numericCode) {
-            // Try to look up the currency code in the instances table.
-            // This does the null pointer check as a side effect.
-            // Also, if there already is an entry, the currencyCode must be valid.
-            Currency instance = instances.get(currencyCode);
-            if (instance != null) {
-                return instance;
+        // Try to look up the currency code in the instances table.
+        // This does the null pointer check as a side effect.
+        // Also, if there already is an entry, the currencyCode must be valid.
+        Currency instance = instances.get(currencyCode);
+        if (instance != null) {
+            return instance;
+        }
+
+        if (defaultFractionDigits == Integer.MIN_VALUE) {
+            // Currency code not internally generated, need to verify first
+            // A currency code must have 3 characters and exist in the main table
+            // or in the list of other currencies.
+            if (currencyCode.length() != 3) {
+                throw new IllegalArgumentException();
             }
-
-            if (defaultFractionDigits == Integer.MIN_VALUE) {
-                // Currency code not internally generated, need to verify first
-                // A currency code must have 3 characters and exist in the main table
-                // or in the list of other currencies.
-                if (currencyCode.length() != 3) {
+            char char1 = currencyCode.charAt(0);
+            char char2 = currencyCode.charAt(1);
+            int tableEntry = getMainTableEntry(char1, char2);
+            if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
+                    && tableEntry != INVALID_COUNTRY_ENTRY
+                    && currencyCode.charAt(2) - 'A' == (tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK)) {
+                defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
+                numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
+            } else {
+                // Check for '-' separately so we don't get false hits in the table.
+                if (currencyCode.charAt(2) == '-') {
                     throw new IllegalArgumentException();
                 }
-                char char1 = currencyCode.charAt(0);
-                char char2 = currencyCode.charAt(1);
-                int tableEntry = getMainTableEntry(char1, char2);
-                if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
-                        && tableEntry != INVALID_COUNTRY_ENTRY
-                        && currencyCode.charAt(2) - 'A' == (tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK)) {
-                    defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
-                    numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
-                } else {
-                    // Check for '-' separately so we don't get false hits in the table.
-                    if (currencyCode.charAt(2) == '-') {
-                        throw new IllegalArgumentException();
-                    }
-                    int index = otherCurrencies.indexOf(currencyCode);
-                    if (index == -1) {
-                        throw new IllegalArgumentException();
-                    }
-                    defaultFractionDigits = otherCurrenciesDFD[index / 4];
-                    numericCode = otherCurrenciesNumericCode[index / 4];
+                int index = otherCurrencies.indexOf(currencyCode);
+                if (index == -1) {
+                    throw new IllegalArgumentException();
                 }
+                defaultFractionDigits = otherCurrenciesDFD[index / 4];
+                numericCode = otherCurrenciesNumericCode[index / 4];
             }
+        }
 
-        instance = instances.putIfAbsent(currencyCode,
-                   new Currency(currencyCode, defaultFractionDigits, numericCode));
-        return (instance != null ? instance : instances.get(currencyCode));
+        Currency currencyVal =
+            new Currency(currencyCode, defaultFractionDigits, numericCode);
+        instance = instances.putIfAbsent(currencyCode, currencyVal);
+        return (instance != null ? instance : currencyVal);
     }
 
     /**