1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:28:11 +00:00

LibUnicode: Generate locale subtag data as multiple smaller tables

This commit is preemptive to upcoming commits which add more subtags to
the CLDR generator. Rather than generating a giant HashMap containing
all data, generate more (smaller) Array-based tables. This mimics the
UCD generator. This also allows simpler lookups at runtime since we can
generate index-based lookups into the smaller tables rather easily.

Without this change, adding the remaining locale subtags would result
in the generation and compilation of UnicodeLocale.cpp taking about 30s
on my machine. With this change, it takes about half that. Additionally,
the size of the generated file reduces by about 1.5MB.
This commit is contained in:
Timothy Flynn 2021-08-26 06:56:17 -04:00 committed by Linus Groh
parent b8ad4d302e
commit 6719e5cb17
4 changed files with 91 additions and 69 deletions

View file

@ -162,27 +162,19 @@ String const& default_locale()
bool is_locale_available([[maybe_unused]] StringView locale)
{
#if ENABLE_UNICODE_DATA
static auto const& available_locales = Detail::available_locales();
return available_locales.contains(locale);
return Detail::locale_from_string(locale).has_value();
#else
return false;
#endif
}
Optional<StringView> get_locale_territory_mapping([[maybe_unused]] StringView locale, [[maybe_unused]] StringView code)
Optional<StringView> get_locale_territory_mapping([[maybe_unused]] StringView locale, [[maybe_unused]] StringView territory)
{
#if ENABLE_UNICODE_DATA
static auto const& available_locales = Detail::available_locales();
auto it = available_locales.find(locale);
if (it == available_locales.end())
return {};
if (auto territory = Detail::territory_from_string(code); territory.has_value())
return it->value.territories[to_underlying(*territory)];
#endif
return Detail::get_locale_territory_mapping(locale, territory);
#else
return {};
#endif
}
}