8000 Avoid slices in entries of decomposition tables by glandium · Pull Request #86 · unicode-rs/unicode-normalization · GitHub
[go: up one dir, main page]

Skip to content

Avoid slices in entries of decomposition tables #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions scripts/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,19 @@ def gen_composition_table(canon_comp, out):
def gen_decomposition_tables(canon_decomp, compat_decomp, cjk_compat_variants_decomp, out):
tables = [(canon_decomp, 'canonical'), (compat_decomp, 'compatibility'), (cjk_compat_variants_decomp, 'cjk_compat_variants')]
for table, name in tables:
gen_mph_data(name + '_decomposed', table, "(u32, &'static [char])",
lambda k: "(0x{:x}, &[{}])".format(k,
", ".join("'\\u{%s}'" % hexify(c) for c in table[k])))
offsets = {}
offset = 0
out.write("pub(crate) const %s_DECOMPOSED_CHARS: &[char] = &[\n" % name.upper())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a fixed array avoid the relocations altogether? As in, a %s_DECOMPOSED_CHARS: [char; _] = or so?

Copy link
Contributor Author
@glandium glandium Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tables are const. The slice for the table themselves are not stored in .data.rel.ro at all because of that. So there are actually no relocations for those (also, that would only be one per table, which is not as dramatic as one per entry).

for k, v in table.items():
offsets[k] = offset
offset += len(v)
for c in v:
out.write(" '\\u{%s}',\n" % hexify(c))
# The largest offset must fit in a u16.
assert offset < 65536
out.write("];\n")
gen_mph_data(name + '_decomposed', table, "(u32, (u16, u16))",
lambda k: "(0x{:x}, ({}, {}))".format(k, offsets[k], len(table[k])))

def gen_qc_match(prop_table, out):
out.write(" match c {\n")
Expand Down
3 changes: 3 additions & 0 deletions src/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub(crate) fn canonical_fully_decomposed(c: char) -> Option<&'static [char]> {
pair_lookup_fv_opt,
None,
)
.map(|(start, len)| &CANONICAL_DECOMPOSED_CHARS[start as usize..][..len as usize])
}

pub(crate) fn compatibility_fully_decomposed(c: char) -> Option<&'static [char]> {
Expand All @@ -62,6 +63,7 @@ pub(crate) fn compatibility_fully_decomposed(c: char) -> Option<&'static [char]>
pair_lookup_fv_opt,
None,
)
.map(|(start, len)| &COMPATIBILITY_DECOMPOSED_CHARS[start as usize..][..len as usize])
}

pub(crate) fn cjk_compat_variants_fully_decomposed(c: char) -> Option<&'static [char]> {
Expand All @@ -73,6 +75,7 @@ pub(crate) fn cjk_compat_variants_fully_decomposed(c: char) -> Option<&'static [
pair_lookup_fv_opt,
None,
)
.map(|(start, len)| &CJK_COMPAT_VARIANTS_DECOMPOSED_CHARS[start as usize..][..len as usize])
}

/// Return whether the given character is a combining mark (`General_Category=Mark`)
Expand Down
Loading
0