summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmarks/src/benchmarks/regression/DecimalFormatSymbolsBenchmark.java30
-rw-r--r--ojluni/src/main/java/java/text/DecimalFormatSymbols.java68
2 files changed, 61 insertions, 37 deletions
diff --git a/benchmarks/src/benchmarks/regression/DecimalFormatSymbolsBenchmark.java b/benchmarks/src/benchmarks/regression/DecimalFormatSymbolsBenchmark.java
new file mode 100644
index 0000000000..381b9e14b2
--- /dev/null
+++ b/benchmarks/src/benchmarks/regression/DecimalFormatSymbolsBenchmark.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package benchmarks.regression;
+
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+
+public class DecimalFormatSymbolsBenchmark {
+
+ private static Locale locale = Locale.getDefault(Locale.Category.FORMAT);
+
+ public void time_instantiation(int reps) {
+ for (int i = 0; i < reps; i++) {
+ new DecimalFormatSymbols(locale);
+ }
+ }
+}
diff --git a/ojluni/src/main/java/java/text/DecimalFormatSymbols.java b/ojluni/src/main/java/java/text/DecimalFormatSymbols.java
index 59b8cdc691..070fd1cbd4 100644
--- a/ojluni/src/main/java/java/text/DecimalFormatSymbols.java
+++ b/ojluni/src/main/java/java/text/DecimalFormatSymbols.java
@@ -648,29 +648,36 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
private void initialize( Locale locale ) {
this.locale = locale;
- // Android-changed: Removed use of DecimalFormatSymbolsProvider. Switched to ICU.
- // get resource bundle data - try the cache first
- boolean needCacheUpdate = false;
- Object[] data = cachedLocaleData.get(locale);
- if (data == null) { /* cache miss */
- locale = LocaleData.mapInvalidAndNullLocales(locale);
- LocaleData localeData = LocaleData.get(locale);
- data = new Object[3];
- String[] values = new String[11];
- values[0] = String.valueOf(localeData.decimalSeparator);
- values[1] = String.valueOf(localeData.groupingSeparator);
- values[2] = String.valueOf(localeData.patternSeparator);
- values[3] = localeData.percent;
- values[4] = String.valueOf(localeData.zeroDigit);
- values[5] = "#";
- values[6] = localeData.minusSign;
- values[7] = localeData.exponentSeparator;
- values[8] = localeData.perMill;
- values[9] = localeData.infinity;
- values[10] = localeData.NaN;
- data[0] = values;
- needCacheUpdate = true;
+ // BEGIN Android-changed: Removed use of DecimalFormatSymbolsProvider. Switched to ICU.
+ /*
+ // get resource bundle data
+ LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
+ // Avoid potential recursions
+ if (!(adapter instanceof ResourceBundleBasedAdapter)) {
+ adapter = LocaleProviderAdapter.getResourceBundleBased();
}
+ Object[] data = adapter.getLocaleResources(locale).getDecimalFormatSymbolsData();
+ */
+ if (locale == null) {
+ throw new NullPointerException("locale");
+ }
+ locale = LocaleData.mapInvalidAndNullLocales(locale);
+ LocaleData localeData = LocaleData.get(locale);
+ Object[] data = new Object[3];
+ String[] values = new String[11];
+ values[0] = String.valueOf(localeData.decimalSeparator);
+ values[1] = String.valueOf(localeData.groupingSeparator);
+ values[2] = String.valueOf(localeData.patternSeparator);
+ values[3] = localeData.percent;
+ values[4] = String.valueOf(localeData.zeroDigit);
+ values[5] = "#";
+ values[6] = localeData.minusSign;
+ values[7] = localeData.exponentSeparator;
+ values[8] = localeData.perMill;
+ values[9] = localeData.infinity;
+ values[10] = localeData.NaN;
+ data[0] = values;
+ // END Android-changed: Removed use of DecimalFormatSymbolsProvider. Switched to ICU.
String[] numberElements = (String[]) data[0];
@@ -707,8 +714,6 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
currencySymbol = currency.getSymbol(locale);
data[1] = intlCurrencySymbol;
data[2] = currencySymbol;
- // Android-added: update cache when necessary.
- needCacheUpdate = true;
}
} else {
// default values
@@ -723,11 +728,6 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
// standard decimal separator for all locales that we support.
// If that changes, add a new entry to NumberElements.
monetarySeparator = decimalSeparator;
-
- // Android-added: update cache when necessary.
- if (needCacheUpdate) {
- cachedLocaleData.putIfAbsent(locale, data);
- }
}
// Android-changed: maybeStripMarkers added in b/26207216, fixed in b/32465689.
@@ -1139,18 +1139,12 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
*/
private int serialVersionOnStream = currentSerialVersion;
- // BEGIN Android-added: cache for locale data and cachedIcuDFS.
- /**
- * cache to hold the NumberElements and the Currency
- * of a Locale.
- */
- private static final ConcurrentHashMap<Locale, Object[]> cachedLocaleData = new ConcurrentHashMap<>(3);
-
+ // BEGIN Android-added: cache for cachedIcuDFS.
/**
* Lazily created cached instance of an ICU DecimalFormatSymbols that's equivalent to this one.
* This field is reset to null whenever any of the relevant fields of this class are modified
* and will be re-created by {@link #getIcuDecimalFormatSymbols()} as necessary.
*/
private transient android.icu.text.DecimalFormatSymbols cachedIcuDFS = null;
- // END Android-added: cache for locale data and cachedIcuDFS.
+ // END Android-added: cache for cachedIcuDFS.
}