mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8331932: Startup regressions in 23-b13
Reviewed-by: alanb, naoto, liach
This commit is contained in:
parent
7db6a3f0ee
commit
d654124502
4 changed files with 56 additions and 16 deletions
|
@ -48,6 +48,7 @@ import java.io.Serializable;
|
|||
import java.text.DateFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.spi.LocaleNameProvider;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -980,29 +981,36 @@ public final class Locale implements Cloneable, Serializable {
|
|||
return getInstance(baseloc, extensions);
|
||||
}
|
||||
|
||||
|
||||
static Locale getInstance(BaseLocale baseloc, LocaleExtensions extensions) {
|
||||
if (extensions == null) {
|
||||
Locale locale = CONSTANT_LOCALES.get(baseloc);
|
||||
if (locale != null) {
|
||||
return locale;
|
||||
}
|
||||
return LOCALE_CACHE.computeIfAbsent(baseloc, Locale::createLocale);
|
||||
return LOCALE_CACHE.computeIfAbsent(baseloc, LOCALE_CREATOR);
|
||||
} else {
|
||||
LocaleKey key = new LocaleKey(baseloc, extensions);
|
||||
return LOCALE_CACHE.computeIfAbsent(key, Locale::createLocale);
|
||||
return LOCALE_CACHE.computeIfAbsent(key, LOCALE_CREATOR);
|
||||
}
|
||||
}
|
||||
|
||||
private static final ReferencedKeyMap<Object, Locale> LOCALE_CACHE = ReferencedKeyMap.create(true, ConcurrentHashMap::new);
|
||||
private static Locale createLocale(Object key) {
|
||||
if (key instanceof BaseLocale base) {
|
||||
return new Locale(base, null);
|
||||
private static final ReferencedKeyMap<Object, Locale> LOCALE_CACHE
|
||||
= ReferencedKeyMap.create(true, ReferencedKeyMap.concurrentHashMapSupplier());
|
||||
|
||||
private static final Function<Object, Locale> LOCALE_CREATOR = new Function<>() {
|
||||
@Override
|
||||
public Locale apply(Object key) {
|
||||
if (key instanceof BaseLocale base) {
|
||||
return new Locale(base, null);
|
||||
}
|
||||
LocaleKey lk = (LocaleKey)key;
|
||||
return new Locale(lk.base, lk.exts);
|
||||
}
|
||||
LocaleKey lk = (LocaleKey)key;
|
||||
return new Locale(lk.base, lk.exts);
|
||||
}
|
||||
};
|
||||
|
||||
private static final class LocaleKey {
|
||||
|
||||
private final BaseLocale base;
|
||||
private final LocaleExtensions exts;
|
||||
private final int hash;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue