diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2020-03-21 18:01:50 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2020-03-21 18:01:50 -0400 |
| commit | af243d4d91400e071a5b8fe5041f55f07fd8a928 (patch) | |
| tree | 102c4febd72514917382c580a0c4f06082ff0d36 | |
| parent | a7ec6f8fe0fb10fa91ac40f68beccd2675cba50c (diff) | |
| download | rust-af243d4d91400e071a5b8fe5041f55f07fd8a928.tar.gz rust-af243d4d91400e071a5b8fe5041f55f07fd8a928.zip | |
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.
| -rw-r--r-- | src/libcore/unicode/unicode_data.rs | 8 | ||||
| -rw-r--r-- | src/tools/unicode-table-generator/src/range_search.rs | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/libcore/unicode/unicode_data.rs b/src/libcore/unicode/unicode_data.rs index aea923e9075..660b91b6025 100644 --- a/src/libcore/unicode/unicode_data.rs +++ b/src/libcore/unicode/unicode_data.rs @@ -27,11 +27,11 @@ fn range_search< } else { return false; }; - let idx = bitset_chunk_idx[(chunk_idx as usize)][chunk_piece] as usize; - let word = if idx < CANONICAL { - bitset_canonical[idx] + let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize; + let word = if let Some(word) = bitset_canonical.get(idx) { + *word } else { - let (real_idx, mapping) = bitset_canonicalized[idx - CANONICAL]; + let (real_idx, mapping) = bitset_canonicalized[idx - bitset_canonical.len()]; let mut word = bitset_canonical[real_idx as usize]; let should_invert = mapping & (1 << 6) != 0; if should_invert { diff --git a/src/tools/unicode-table-generator/src/range_search.rs b/src/tools/unicode-table-generator/src/range_search.rs index 12efa5a9f83..b57fd2c1d86 100644 --- a/src/tools/unicode-table-generator/src/range_search.rs +++ b/src/tools/unicode-table-generator/src/range_search.rs @@ -25,11 +25,11 @@ fn range_search< } else { return false; }; - let idx = bitset_chunk_idx[(chunk_idx as usize)][chunk_piece] as usize; - let word = if idx < CANONICAL { - bitset_canonical[idx] + let idx = bitset_chunk_idx[chunk_idx as usize][chunk_piece] as usize; + let word = if let Some(word) = bitset_canonical.get(idx) { + *word } else { - let (real_idx, mapping) = bitset_canonicalized[idx - CANONICAL]; + let (real_idx, mapping) = bitset_canonicalized[idx - bitset_canonical.len()]; let mut word = bitset_canonical[real_idx as usize]; let should_invert = mapping & (1 << 6) != 0; if should_invert { |
