Skip to content

Commit 90ebc24

Browse files
committed
Use intrinsics::assume instead of hint::assert_unchecked.
1 parent 2272558 commit 90ebc24

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

library/core/src/unicode/unicode_data.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ unsafe fn skip_search<const SOR: usize, const OFFSETS: usize>(
9494
// correct location cannot be past it, so `Err(idx) => idx != length` either.
9595
//
9696
// This means that we can avoid bounds checking for the accesses below, too.
97-
unsafe { crate::hint::assert_unchecked(last_idx < SOR) };
97+
//
98+
// We need to use `intrinsics::assume` since the `panic_nounwind` contained
99+
// in `hint::assert_unchecked` may not be optimized out.
100+
unsafe { crate::intrinsics::assume(last_idx < SOR) };
98101

99102
let mut offset_idx = short_offset_runs[last_idx].start_index();
100103
let length = if let Some(next) = short_offset_runs.get(last_idx + 1) {
@@ -112,7 +115,10 @@ unsafe fn skip_search<const SOR: usize, const OFFSETS: usize>(
112115
// SAFETY: It is guaranteed that `length <= OFFSETS - offset_idx`,
113116
// so it follows that `length - 1 + offset_idx < OFFSETS`, therefore
114117
// `offset_idx < OFFSETS` is always true in this loop.
115-
unsafe { crate::hint::assert_unchecked(offset_idx < OFFSETS) };
118+
//
119+
// We need to use `intrinsics::assume` since the `panic_nounwind` contained
120+
// in `hint::assert_unchecked` may not be optimized out.
121+
unsafe { crate::intrinsics::assume(offset_idx < OFFSETS) };
116122
let offset = offsets[offset_idx];
117123
prefix_sum += offset as u32;
118124
if prefix_sum > total {

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ unsafe fn skip_search<const SOR: usize, const OFFSETS: usize>(
9292
// correct location cannot be past it, so `Err(idx) => idx != length` either.
9393
//
9494
// This means that we can avoid bounds checking for the accesses below, too.
95-
unsafe { crate::hint::assert_unchecked(last_idx < SOR) };
95+
//
96+
// We need to use `intrinsics::assume` since the `panic_nounwind` contained
97+
// in `hint::assert_unchecked` may not be optimized out.
98+
unsafe { crate::intrinsics::assume(last_idx < SOR) };
9699

97100
let mut offset_idx = short_offset_runs[last_idx].start_index();
98101
let length = if let Some(next) = short_offset_runs.get(last_idx + 1) {
@@ -110,7 +113,10 @@ unsafe fn skip_search<const SOR: usize, const OFFSETS: usize>(
110113
// SAFETY: It is guaranteed that `length <= OFFSETS - offset_idx`,
111114
// so it follows that `length - 1 + offset_idx < OFFSETS`, therefore
112115
// `offset_idx < OFFSETS` is always true in this loop.
113-
unsafe { crate::hint::assert_unchecked(offset_idx < OFFSETS) };
116+
//
117+
// We need to use `intrinsics::assume` since the `panic_nounwind` contained
118+
// in `hint::assert_unchecked` may not be optimized out.
119+
unsafe { crate::intrinsics::assume(offset_idx < OFFSETS) };
114120
let offset = offsets[offset_idx];
115121
prefix_sum += offset as u32;
116122
if prefix_sum > total {

0 commit comments

Comments
 (0)