Skip to content

Commit 5dfd1ec

Browse files
author
Markus Westerlind
committed
refactor: Avoid doing unnecessary bit operations in rust's const eval
1 parent 7612975 commit 5dfd1ec

File tree

3 files changed

+1589
-1582
lines changed

3 files changed

+1589
-1582
lines changed

idna/src/make_uts46_mapping_table.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,15 @@ def merge_single_char_ranges(ranges):
162162

163163
print("static INDEX_TABLE: &'static [u16] = &[")
164164

165+
SINGLE_MARKER = 1 << 15
166+
165167
offset = 0
166168
for ranges in optimized_ranges:
169+
assert offset < SINGLE_MARKER
170+
167171
block_len = len(ranges)
168-
single = (1 << 15) if block_len == 1 else 0
169-
print(" %s | %s, " % (offset, single))
172+
single = SINGLE_MARKER if block_len == 1 else 0
173+
print(" %s," % (offset | single))
170174
offset += block_len
171175

172176
print("];\n")

idna/src/uts46.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ fn find_char(codepoint: char) -> &'static Mapping {
6969
}
7070
});
7171
r.ok().map(|i| {
72+
const SINGLE_MARKER: u16 = 1 << 15;
73+
7274
let x = INDEX_TABLE[i];
73-
let single = (x & (1 << 15)) != 0;
74-
let offset = !(1 << 15) & x;
75+
let single = (x & SINGLE_MARKER) != 0;
76+
let offset = !SINGLE_MARKER & x;
77+
7578
if single {
7679
&MAPPING_TABLE[offset as usize]
7780
} else {

0 commit comments

Comments
 (0)