Skip to content

Commit 9693245

Browse files
committed
Use intrinsics::assume instead of hint::assert_unchecked.
1 parent 09bc972 commit 9693245

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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 {

0 commit comments

Comments
 (0)