8283324: CLDRConverter run time increased by 3x

Reviewed-by: ihse
This commit is contained in:
Naoto Sato 2022-04-21 22:23:24 +00:00
parent ec4fb47b90
commit f6e9ca0cbe
2 changed files with 16 additions and 6 deletions

View File

@ -847,19 +847,24 @@ public class CLDRConverter {
"DateTimePatternChars", "DateTimePatternChars",
"PluralRules", "PluralRules",
"DayPeriodRules", "DayPeriodRules",
"DateFormatItem", "DateFormatItemInputRegions.allowed",
"DateFormatItemInputRegions.preferred",
}; };
static final Set<String> availableSkeletons = new HashSet<>();
private static Map<String, Object> extractFormatData(Map<String, Object> map, String id) { private static Map<String, Object> extractFormatData(Map<String, Object> map, String id) {
Map<String, Object> formatData = new LinkedHashMap<>(); Map<String, Object> formatData = new LinkedHashMap<>();
for (CalendarType calendarType : CalendarType.values()) { for (CalendarType calendarType : CalendarType.values()) {
String prefix = calendarType.keyElementName(); String prefix = calendarType.keyElementName();
Arrays.stream(FORMAT_DATA_ELEMENTS) Arrays.stream(FORMAT_DATA_ELEMENTS)
.flatMap(elem -> map.keySet().stream().filter(k -> k.startsWith(prefix + elem))) .forEach(elem -> {
.forEach(key -> { var key = prefix + elem;
copyIfPresent(map, "java.time." + key, formatData); copyIfPresent(map, "java.time." + key, formatData);
copyIfPresent(map, key, formatData); copyIfPresent(map, key, formatData);
}); });
availableSkeletons.forEach(s ->
copyIfPresent(map, prefix + "DateFormatItem." + s, formatData));
} }
for (String key : map.keySet()) { for (String key : map.keySet()) {

View File

@ -768,9 +768,14 @@ class LDMLParseHandler extends AbstractLDMLHandler<Object> {
case "dateFormatItem": case "dateFormatItem":
{ {
// for FormatData // for FormatData
prefix = (currentCalendarType == null) ? "" : currentCalendarType.keyElementName(); if (currentCalendarType != null) {
var skeleton = attributes.getValue("id");
CLDRConverter.availableSkeletons.add(skeleton);
pushStringEntry(qName, attributes, pushStringEntry(qName, attributes,
prefix + Bundle.DATEFORMATITEM_KEY_PREFIX + attributes.getValue("id")); currentCalendarType.keyElementName() + Bundle.DATEFORMATITEM_KEY_PREFIX + skeleton);
} else {
pushIgnoredContainer(qName);
}
} }
break; break;