浏览代码

LibLocale: Decide to skip parsing CLDR calendars a little earlier

We currently parse each CLDR calendar, then decide based on its primary
key whether we want to skip it. Instead, we can decide to skip it based
on its file name.

This reduces the runtime of GenerateLocaleData from 2.03s to 1.97s.
Timothy Flynn 1 年之前
父节点
当前提交
c9b39c0c39
共有 1 个文件被更改,包括 8 次插入8 次删除
  1. 8 8
      Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp

+ 8 - 8
Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp

@@ -833,12 +833,17 @@ static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path,
     KeywordList keywords {};
     KeywordList keywords {};
 
 
     TRY(Core::Directory::for_each_entry(locale_dates_path, Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
     TRY(Core::Directory::for_each_entry(locale_dates_path, Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
-        auto locale_calendars_path = LexicalPath::join(directory.path().string(), entry.name).string();
+        if (!entry.name.starts_with("ca-"sv))
+            return IterationDecision::Continue;
 
 
-        LexicalPath calendars_path(move(locale_calendars_path));
-        if (!calendars_path.basename().starts_with("ca-"sv))
+        // The generic calendar is not a supported Unicode calendar key, so skip it:
+        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar#unicode_calendar_keys
+        if (entry.name == "ca-generic.json"sv)
             return IterationDecision::Continue;
             return IterationDecision::Continue;
 
 
+        auto locale_calendars_path = LexicalPath::join(directory.path().string(), entry.name).string();
+        LexicalPath calendars_path(move(locale_calendars_path));
+
         auto calendars = TRY(read_json_file(calendars_path.string()));
         auto calendars = TRY(read_json_file(calendars_path.string()));
         auto const& main_object = calendars.as_object().get_object("main"sv).value();
         auto const& main_object = calendars.as_object().get_object("main"sv).value();
         auto const& locale_object = main_object.get_object(calendars_path.parent().basename()).value();
         auto const& locale_object = main_object.get_object(calendars_path.parent().basename()).value();
@@ -846,11 +851,6 @@ static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path,
         auto const& calendars_object = dates_object.get_object("calendars"sv).value();
         auto const& calendars_object = dates_object.get_object("calendars"sv).value();
 
 
         calendars_object.for_each_member([&](auto calendar_name, JsonValue const&) {
         calendars_object.for_each_member([&](auto calendar_name, JsonValue const&) {
-            // The generic calendar is not a supported Unicode calendar key, so skip it:
-            // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar#unicode_calendar_keys
-            if (calendar_name == "generic"sv)
-                return;
-
             if (auto calendar_alias = find_keyword_alias("ca"sv, calendar_name, cldr); calendar_alias.has_value())
             if (auto calendar_alias = find_keyword_alias("ca"sv, calendar_name, cldr); calendar_alias.has_value())
                 calendar_name = calendar_alias.release_value();
                 calendar_name = calendar_alias.release_value();