1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:07:34 +00:00

LibUnicode: Generate standalone compile-time arrays for simple casing

Currently, all casing information (simple and special) are stored in a
compile-time array of size 34,626, then statically copied to a hash map
at runtime. In an effort to reduce the resulting memory usage, store the
simple casing rules in standalone compile-time arrays. The uppercase map
is size 1,450 and the lowercase map is size 1,433. Any code point not in
a map will implicitly have an identity mapping.
This commit is contained in:
Timothy Flynn 2021-10-09 18:12:57 -04:00 committed by Andreas Kling
parent 7defb893a9
commit da4b8897a7
2 changed files with 78 additions and 10 deletions

View file

@ -213,10 +213,7 @@ static SpecialCasing const* find_matching_special_case(Utf8View const& string, O
u32 to_unicode_lowercase(u32 code_point)
{
#if ENABLE_UNICODE_DATA
auto unicode_data = Detail::unicode_data_for_code_point(code_point);
if (unicode_data.has_value())
return unicode_data->simple_lowercase_mapping;
return code_point;
return Detail::simple_lowercase_mapping(code_point);
#else
return AK::to_ascii_lowercase(code_point);
#endif
@ -225,10 +222,7 @@ u32 to_unicode_lowercase(u32 code_point)
u32 to_unicode_uppercase(u32 code_point)
{
#if ENABLE_UNICODE_DATA
auto unicode_data = Detail::unicode_data_for_code_point(code_point);
if (unicode_data.has_value())
return unicode_data->simple_uppercase_mapping;
return code_point;
return Detail::simple_uppercase_mapping(code_point);
#else
return AK::to_ascii_uppercase(code_point);
#endif
@ -255,7 +249,7 @@ String to_unicode_lowercase_full(StringView const& string, [[maybe_unused]] Opti
auto const* special_casing = find_matching_special_case(view, locale, index, byte_length, *unicode_data);
if (!special_casing) {
builder.append_code_point(unicode_data->simple_lowercase_mapping);
builder.append_code_point(to_unicode_lowercase(code_point));
continue;
}
@ -290,7 +284,7 @@ String to_unicode_uppercase_full(StringView const& string, [[maybe_unused]] Opti
auto const* special_casing = find_matching_special_case(view, locale, index, byte_length, *unicode_data);
if (!special_casing) {
builder.append_code_point(unicode_data->simple_uppercase_mapping);
builder.append_code_point(to_unicode_uppercase(code_point));
continue;
}