8055088: Optimization for locale resources loading isn't working
Reviewed-by: naoto
This commit is contained in:
parent
391a556d14
commit
46c981faef
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,7 +34,8 @@ LOCALE_FILES := $(shell $(FIND) $(JDK_TOPDIR)/src/*/share/classes \
|
||||
-name "TimeZoneNames_*.java" -o -name "TimeZoneNames_*.properties" -o \
|
||||
-name "LocaleNames_*.java" -o -name "LocaleNames_*.properties" -o \
|
||||
-name "CurrencyNames_*.java" -o -name "CurrencyNames_*.properties" -o \
|
||||
-name "CalendarData_*.java" -o -name "CalendarData_*.properties")
|
||||
-name "CalendarData_*.java" -o -name "CalendarData_*.properties" -o \
|
||||
-name "BreakIteratorInfo_*.java" -o -name "BreakIteratorRules_*.java")
|
||||
|
||||
# Then translate the locale files into for example: FormatData_sv
|
||||
LOCALE_RESOURCES := $(sort $(subst .properties,,$(subst .java,,$(notdir $(LOCALE_FILES)))))
|
||||
@ -86,6 +87,12 @@ $(eval $(call CaptureLocale,FormatData))
|
||||
#sun.text.resources.CollationData
|
||||
$(eval $(call CaptureLocale,CollationData))
|
||||
|
||||
#sun.text.resources.BreakIteratorInfo
|
||||
$(eval $(call CaptureLocale,BreakIteratorInfo))
|
||||
|
||||
#sun.text.resources.BreakIteratorRules
|
||||
$(eval $(call CaptureLocale,BreakIteratorRules))
|
||||
|
||||
#sun.util.resources.TimeZoneNames
|
||||
$(eval $(call CaptureLocale,TimeZoneNames))
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,6 +30,7 @@ import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.spi.BreakIteratorProvider;
|
||||
import java.text.spi.CollatorProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
@ -102,6 +103,9 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
|
||||
@Override
|
||||
protected Set<String> createLanguageTagSet(String category) {
|
||||
ResourceBundle rb = ResourceBundle.getBundle("sun.util.cldr.CLDRLocaleDataMetaInfo", Locale.ROOT);
|
||||
if (rb.containsKey(category)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
String supportedLocaleString = rb.getString(category);
|
||||
Set<String> tagset = new HashSet<>();
|
||||
StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,6 +34,7 @@ import java.text.spi.DateFormatProvider;
|
||||
import java.text.spi.DateFormatSymbolsProvider;
|
||||
import java.text.spi.DecimalFormatSymbolsProvider;
|
||||
import java.text.spi.NumberFormatProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
@ -356,6 +357,9 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements R
|
||||
|
||||
protected Set<String> createLanguageTagSet(String category) {
|
||||
String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category);
|
||||
if (supportedLocaleString == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<String> tagset = new HashSet<>();
|
||||
StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
|
||||
while (tokens.hasMoreTokens()) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -57,6 +57,12 @@ public class LocaleDataMetaInfo {
|
||||
resourceNameToLocales.put("CollationData",
|
||||
" #CollationData_ENLocales# | #CollationData_NonENLocales# ");
|
||||
|
||||
resourceNameToLocales.put("BreakIteratorInfo",
|
||||
" #BreakIteratorInfo_ENLocales# | #BreakIteratorInfo_NonENLocales# ");
|
||||
|
||||
resourceNameToLocales.put("BreakIteratorRules",
|
||||
" #BreakIteratorRules_ENLocales# | #BreakIteratorRules_NonENLocales# ");
|
||||
|
||||
resourceNameToLocales.put("TimeZoneNames",
|
||||
" #TimeZoneNames_ENLocales# | #TimeZoneNames_NonENLocales# ");
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -295,7 +295,7 @@ public abstract class LocaleProviderAdapter {
|
||||
* A utility method for implementing the default LocaleServiceProvider.isSupportedLocale
|
||||
* for the JRE, CLDR, and FALLBACK adapters.
|
||||
*/
|
||||
static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) {
|
||||
public static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) {
|
||||
assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK;
|
||||
if (Locale.ROOT.equals(locale)) {
|
||||
return true;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -48,8 +48,11 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import sun.util.locale.provider.JRELocaleProviderAdapter;
|
||||
import sun.util.locale.provider.LocaleDataMetaInfo;
|
||||
import sun.util.locale.provider.LocaleProviderAdapter;
|
||||
import static sun.util.locale.provider.LocaleProviderAdapter.Type.CLDR;
|
||||
import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE;
|
||||
|
||||
/**
|
||||
@ -204,35 +207,23 @@ public class LocaleData {
|
||||
@Override
|
||||
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
|
||||
List<Locale> candidates = super.getCandidateLocales(baseName, locale);
|
||||
/* Get the locale string list from LocaleDataMetaInfo class. */
|
||||
String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName);
|
||||
|
||||
if (localeString != null && localeString.length() != 0) {
|
||||
for (Iterator<Locale> l = candidates.iterator(); l.hasNext();) {
|
||||
Locale loc = l.next();
|
||||
String lstr;
|
||||
if (loc.getScript().length() > 0) {
|
||||
lstr = loc.toLanguageTag().replace('-', '_');
|
||||
} else {
|
||||
lstr = loc.toString();
|
||||
int idx = lstr.indexOf("_#");
|
||||
if (idx >= 0) {
|
||||
lstr = lstr.substring(0, idx);
|
||||
}
|
||||
}
|
||||
/* Every locale string in the locale string list returned from
|
||||
the above getSupportedLocaleString is enclosed
|
||||
within two white spaces so that we could check some locale
|
||||
such as "en".
|
||||
*/
|
||||
if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) {
|
||||
l.remove();
|
||||
// Weed out Locales which are known to have no resource bundles
|
||||
int lastDot = baseName.lastIndexOf('.');
|
||||
String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
|
||||
LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
|
||||
LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
|
||||
Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
|
||||
if (!langtags.isEmpty()) {
|
||||
for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
|
||||
if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Force fallback to Locale.ENGLISH for CLDR time zone names support
|
||||
if (locale.getLanguage() != "en"
|
||||
&& baseName.contains(CLDR) && baseName.endsWith("TimeZoneNames")) {
|
||||
&& type == CLDR && category.equals("TimeZoneNames")) {
|
||||
candidates.add(candidates.size() - 1, Locale.ENGLISH);
|
||||
}
|
||||
return candidates;
|
||||
@ -254,7 +245,7 @@ public class LocaleData {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final String CLDR = ".cldr";
|
||||
private static final String DOTCLDR = ".cldr";
|
||||
|
||||
/**
|
||||
* Changes baseName to its per-language package name and
|
||||
@ -275,8 +266,8 @@ public class LocaleData {
|
||||
assert JRE.getUtilResourcesPackage().length()
|
||||
== JRE.getTextResourcesPackage().length();
|
||||
int index = JRE.getUtilResourcesPackage().length();
|
||||
if (baseName.indexOf(CLDR, index) > 0) {
|
||||
index += CLDR.length();
|
||||
if (baseName.indexOf(DOTCLDR, index) > 0) {
|
||||
index += DOTCLDR.length();
|
||||
}
|
||||
newBaseName = baseName.substring(0, index + 1) + lang
|
||||
+ baseName.substring(index);
|
||||
|
Loading…
Reference in New Issue
Block a user