Skip to content

Commit e035f89

Browse files
author
Markus Westerlind
committed
perf: Split the uts46 table for better cache locality (-4%)
1 parent c493261 commit e035f89

File tree

3 files changed

+15247
-7622
lines changed

3 files changed

+15247
-7622
lines changed

idna/src/make_uts46_mapping_table.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
// except according to those terms.
2424
2525
// Generated by make_idna_table.py
26-
27-
static TABLE: &'static [Range] = &[
2826
''')
2927

3028
txt = open("IdnaMappingTable.txt")
@@ -123,12 +121,23 @@ def mergeable_key(r):
123121
unicode_str = group[0][3]
124122
optimized_ranges.append((first, last, mapping, unicode_str))
125123

124+
125+
print("static TABLE: &'static [Range] = &[")
126+
127+
for (first, last, mapping, unicode_str) in optimized_ranges:
128+
if unicode_str is not None:
129+
mapping += rust_slice(strtab_slice(unicode_str))
130+
print(" Range { from: '%s', to: '%s', }," % (escape_char(char(first)),
131+
escape_char(char(last))))
132+
133+
print("];\n")
134+
135+
print("static MAPPING_TABLE: &'static [Mapping] = &[")
136+
126137
for (first, last, mapping, unicode_str) in optimized_ranges:
127138
if unicode_str is not None:
128139
mapping += rust_slice(strtab_slice(unicode_str))
129-
print(" Range { from: '%s', to: '%s', mapping: %s }," % (escape_char(char(first)),
130-
escape_char(char(last)),
131-
mapping))
140+
print(" %s," % mapping)
132141

133142
print("];\n")
134143

idna/src/uts46.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ enum Mapping {
5555
struct Range {
5656
from: char,
5757
to: char,
58-
mapping: Mapping,
5958
}
6059

6160
fn find_char(codepoint: char) -> &'static Mapping {
@@ -68,7 +67,7 @@ fn find_char(codepoint: char) -> &'static Mapping {
6867
Equal
6968
}
7069
});
71-
r.ok().map(|i| &TABLE[i].mapping).unwrap()
70+
r.ok().map(|i| &MAPPING_TABLE[i]).unwrap()
7271
}
7372

7473
fn map_char(codepoint: char, flags: Flags, output: &mut String, errors: &mut Vec<Error>) {

0 commit comments

Comments
 (0)