1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-30 15:12:07 +00:00

Meta+LibUnicode: Avoid relocations for static unicode data

Previously the s_decomposition_mappings variable would refer to other
data in s_decomposition_mappings_data. This would cause thousands of
avoidable relocations at load time.

This saves about 128kB RAM for each process which uses LibUnicode.
This commit is contained in:
Gunnar Beutner 2022-11-06 07:08:56 +01:00 committed by Gunnar Beutner
parent fb71df5cb1
commit 2d3567ee92
3 changed files with 26 additions and 12 deletions

View file

@ -14,8 +14,8 @@
namespace Unicode {
Optional<CodePointDecomposition const&> __attribute__((weak)) code_point_decomposition(u32) { return {}; }
Span<CodePointDecomposition const> __attribute__((weak)) code_point_decompositions() { return {}; }
Optional<CodePointDecomposition const> __attribute__((weak)) code_point_decomposition(u32) { return {}; }
Optional<CodePointDecomposition const> __attribute__((weak)) code_point_decomposition_by_index(size_t) { return {}; }
NormalizationForm normalization_form_from_string(StringView form)
{
@ -122,7 +122,11 @@ static u32 combine_code_points(u32 a, u32 b)
{
Array<u32, 2> const points { a, b };
// FIXME: Do something better than linear search to find reverse mappings.
for (auto const& mapping : Unicode::code_point_decompositions()) {
for (size_t index = 0;; ++index) {
auto mapping_maybe = Unicode::code_point_decomposition_by_index(index);
if (!mapping_maybe.has_value())
break;
auto& mapping = mapping_maybe.value();
if (mapping.tag == CompatibilityFormattingTag::Canonical && mapping.decomposition == points) {
if (code_point_has_property(mapping.code_point, Property::Full_Composition_Exclusion))
continue;