1313{
1414 type Output = I :: Output ;
1515
16- #[ inline]
16+ #[ inline( always ) ]
1717 fn index ( & self , index : I ) -> & I :: Output {
1818 index. index ( self )
1919 }
@@ -24,7 +24,7 @@ impl<T, I> ops::IndexMut<I> for [T]
2424where
2525 I : SliceIndex < [ T ] > ,
2626{
27- #[ inline]
27+ #[ inline( always ) ]
2828 fn index_mut ( & mut self , index : I ) -> & mut I :: Output {
2929 index. index_mut ( self )
3030 }
@@ -227,14 +227,16 @@ unsafe impl<T> SliceIndex<[T]> for usize {
227227 unsafe fn get_unchecked ( self , slice : * const [ T ] ) -> * const T {
228228 debug_assert_nounwind ! (
229229 self < slice. len( ) ,
230- "slice::get_unchecked requires that the index is within the slice" ,
230+ "slice::get_unchecked requires that the index is within the slice"
231231 ) ;
232232 // SAFETY: the caller guarantees that `slice` is not dangling, so it
233233 // cannot be longer than `isize::MAX`. They also guarantee that
234234 // `self` is in bounds of `slice` so `self` cannot overflow an `isize`,
235235 // so the call to `add` is safe.
236236 unsafe {
237- crate :: hint:: assert_unchecked ( self < slice. len ( ) ) ;
237+ // Use intrinsics::assume instead of hint::assert_unchecked so that we don't check the
238+ // precondition of this function twice.
239+ crate :: intrinsics:: assume ( self < slice. len ( ) ) ;
238240 slice. as_ptr ( ) . add ( self )
239241 }
240242 }
@@ -243,7 +245,7 @@ unsafe impl<T> SliceIndex<[T]> for usize {
243245 unsafe fn get_unchecked_mut ( self , slice : * mut [ T ] ) -> * mut T {
244246 debug_assert_nounwind ! (
245247 self < slice. len( ) ,
246- "slice::get_unchecked_mut requires that the index is within the slice" ,
248+ "slice::get_unchecked_mut requires that the index is within the slice"
247249 ) ;
248250 // SAFETY: see comments for `get_unchecked` above.
249251 unsafe { slice. as_mut_ptr ( ) . add ( self ) }
@@ -305,8 +307,9 @@ unsafe impl<T> SliceIndex<[T]> for ops::IndexRange {
305307 unsafe fn get_unchecked_mut ( self , slice : * mut [ T ] ) -> * mut [ T ] {
306308 debug_assert_nounwind ! (
307309 self . end( ) <= slice. len( ) ,
308- "slice::get_unchecked_mut requires that the index is within the slice" ,
310+ "slice::get_unchecked_mut requires that the index is within the slice"
309311 ) ;
312+
310313 // SAFETY: see comments for `get_unchecked` above.
311314 unsafe { ptr:: slice_from_raw_parts_mut ( slice. as_mut_ptr ( ) . add ( self . start ( ) ) , self . len ( ) ) }
312315 }
@@ -361,8 +364,9 @@ unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
361364 unsafe fn get_unchecked ( self , slice : * const [ T ] ) -> * const [ T ] {
362365 debug_assert_nounwind ! (
363366 self . end >= self . start && self . end <= slice. len( ) ,
364- "slice::get_unchecked requires that the range is within the slice" ,
367+ "slice::get_unchecked requires that the range is within the slice"
365368 ) ;
369+
366370 // SAFETY: the caller guarantees that `slice` is not dangling, so it
367371 // cannot be longer than `isize::MAX`. They also guarantee that
368372 // `self` is in bounds of `slice` so `self` cannot overflow an `isize`,
@@ -377,7 +381,7 @@ unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
377381 unsafe fn get_unchecked_mut ( self , slice : * mut [ T ] ) -> * mut [ T ] {
378382 debug_assert_nounwind ! (
379383 self . end >= self . start && self . end <= slice. len( ) ,
380- "slice::get_unchecked_mut requires that the range is within the slice" ,
384+ "slice::get_unchecked_mut requires that the range is within the slice"
381385 ) ;
382386 // SAFETY: see comments for `get_unchecked` above.
383387 unsafe {
0 commit comments