Skip to content

Commit fca5694

Browse files
author
Markus Westerlind
committed
Store the first indicator directly into the u16
Since we don't need all bits we can store the first indicator in `u16` directly and save another 3kb
1 parent 281958c commit fca5694

File tree

3 files changed

+1585
-1582
lines changed

3 files changed

+1585
-1582
lines changed

idna/src/make_uts46_mapping_table.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ def merge_single_char_ranges(ranges):
155155

156156
print("];\n")
157157

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

160160
offset = 0
161161
for ranges in optimized_ranges:
162162
block_len = len(ranges)
163-
print("(%s, %s), " % (offset, "true" if block_len == 1 else "false"))
163+
single = (1 << 15) if block_len == 1 else 0
164+
print(" %s | %s, " % (offset, single))
164165
offset += block_len
165166

166167
print("];\n")

idna/src/uts46.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ fn find_char(codepoint: char) -> &'static Mapping {
6868
}
6969
});
7070
r.ok().map(|i| {
71-
let (offset, single) = INDEX_TABLE[i];
71+
let x = INDEX_TABLE[i];
72+
let single = (x & (1 << 15)) != 0;
73+
let offset = !(1 << 15) & x;
7274
if single {
7375
&MAPPING_TABLE[offset as usize]
7476
} else {
75-
&MAPPING_TABLE[(offset + codepoint as u16 - TABLE[i].from as u16) as usize]
77+
&MAPPING_TABLE[(offset + (codepoint as u16 - TABLE[i].from as u16)) as usize]
7678
}
7779
}).unwrap()
7880
}

0 commit comments

Comments
 (0)