8304976: Optimize DateTimeFormatterBuilder.ZoneTextPrinterParser.getTree()

Reviewed-by: naoto
This commit is contained in:
Sergey Tsypanov 2023-03-29 18:32:14 +00:00 committed by Naoto Sato
parent d063b8964f
commit 438c969b7b
2 changed files with 61 additions and 5 deletions

View file

@ -4516,9 +4516,9 @@ public final class DateTimeFormatterBuilder {
// cache per instance for now
private final Map<Locale, Entry<Integer, SoftReference<PrefixTree>>>
cachedTree = new HashMap<>();
cachedTree = HashMap.newHashMap(1);
private final Map<Locale, Entry<Integer, SoftReference<PrefixTree>>>
cachedTreeCI = new HashMap<>();
cachedTreeCI = HashMap.newHashMap(1);
@Override
protected PrefixTree getTree(DateTimeParseContext context) {
@ -4527,9 +4527,8 @@ public final class DateTimeFormatterBuilder {
}
Locale locale = context.getLocale();
boolean isCaseSensitive = context.isCaseSensitive();
Set<String> regionIds = new HashSet<>(ZoneRulesProvider.getAvailableZoneIds());
Set<String> nonRegionIds = new HashSet<>(64);
int regionIdsSize = regionIds.size();
Set<String> availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
int regionIdsSize = availableZoneIds.size();
Map<Locale, Entry<Integer, SoftReference<PrefixTree>>> cached =
isCaseSensitive ? cachedTree : cachedTreeCI;
@ -4542,6 +4541,8 @@ public final class DateTimeFormatterBuilder {
(tree = entry.getValue().get()) == null)) {
tree = PrefixTree.newTree(context);
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
Set<String> nonRegionIds = HashSet.newHashSet(64);
Set<String> regionIds = new HashSet<>(availableZoneIds);
for (String[] names : zoneStrings) {
String zid = names[0];
if (!regionIds.remove(zid)) {