Skip to content

Commit 281958c

Browse files
author
Markus Westerlind
committed
Split the uts46 table into one more table to avoid storing slices
`MAPPING_TABLE` were pretty large from the last commit as it contains two pointers for each element. By converting it into a index to another table + a single element indicator to recover most of it (6000 * 8 - 1500 * 4 =) 42kb reduction.
1 parent 94e836c commit 281958c

File tree

3 files changed

+9210
-1587
lines changed

3 files changed

+9210
-1587
lines changed

idna/src/make_uts46_mapping_table.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,23 @@ def merge_single_char_ranges(ranges):
155155

156156
print("];\n")
157157

158-
print("static MAPPING_TABLE: &'static [&[Mapping]] = &[")
158+
print("static INDEX_TABLE: &'static [(u16, bool)] = &[")
159159

160+
offset = 0
160161
for ranges in optimized_ranges:
161-
print("&[", end='')
162+
block_len = len(ranges)
163+
print("(%s, %s), " % (offset, "true" if block_len == 1 else "false"))
164+
offset += block_len
162165

166+
print("];\n")
167+
168+
print("static MAPPING_TABLE: &'static [Mapping] = &[")
169+
170+
for ranges in optimized_ranges:
163171
for (first, last, mapping, unicode_str) in ranges:
164172
if unicode_str is not None:
165173
mapping += rust_slice(strtab_slice(unicode_str))
166-
print("%s, " % mapping, end='')
167-
168-
print("],")
174+
print("%s, " % mapping)
169175

170176
print("];\n")
171177

idna/src/uts46.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ fn find_char(codepoint: char) -> &'static Mapping {
6868
}
6969
});
7070
r.ok().map(|i| {
71-
let xs = &MAPPING_TABLE[i];
72-
if xs.len() == 1 {
73-
&xs[0]
71+
let (offset, single) = INDEX_TABLE[i];
72+
if single {
73+
&MAPPING_TABLE[offset as usize]
7474
} else {
75-
&xs[codepoint as usize - TABLE[i].from as usize]
75+
&MAPPING_TABLE[(offset + codepoint as u16 - TABLE[i].from as u16) as usize]
7676
}
7777
}).unwrap()
7878
}

0 commit comments

Comments
 (0)