Skip to content

Commit af243d4

Browse files
Avoid relying on const parameters to function
LLVM seems to at least sometimes optimize better when the length comes directly from the `len()` of the array vs. an equivalent integer. Also, this allows easier copy/pasting of the function into compiler explorer for experimentation.
1 parent a7ec6f8 commit af243d4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/libcore/unicode/unicode_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ fn range_search<
2727
} else {
2828
return false;
2929
};
30-
let idx = bitset_chunk_idx[(chunk_idx as usize)][chunk_piece] as usize;
31-
let word = if idx < CANONICAL {
32-
bitset_canonical[idx]
30+
let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize;
31+
let word = if let Some(word) = bitset_canonical.get(idx) {
32+
*word
3333
} else {
34-
let (real_idx, mapping) = bitset_canonicalized[idx - CANONICAL];
34+
let (real_idx, mapping) = bitset_canonicalized[idx - bitset_canonical.len()];
3535
let mut word = bitset_canonical[real_idx as usize];
3636
let should_invert = mapping & (1 << 6) != 0;
3737
if should_invert {

src/tools/unicode-table-generator/src/range_search.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn range_search<
2525
} else {
2626
return false;
2727
};
28-
let idx = bitset_chunk_idx[(chunk_idx as usize)][chunk_piece] as usize;
29-
let word = if idx < CANONICAL {
30-
bitset_canonical[idx]
28+
let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize;
29+
let word = if let Some(word) = bitset_canonical.get(idx) {
30+
*word
3131
} else {
32-
let (real_idx, mapping) = bitset_canonicalized[idx - CANONICAL];
32+
let (real_idx, mapping) = bitset_canonicalized[idx - bitset_canonical.len()];
3333
let mut word = bitset_canonical[real_idx as usize];
3434
let should_invert = mapping & (1 << 6) != 0;
3535
if should_invert {

0 commit comments

Comments
 (0)