1616// crate doing wrapping pointer arithmetic with a method that must not wrap won't be the problem if
1717// something does go wrong at runtime.
1818use core:: ffi:: c_int;
19- use core:: intrinsics:: likely;
19+
20+ use crate :: support:: cold_path;
2021
2122const WORD_SIZE : usize = core:: mem:: size_of :: < usize > ( ) ;
2223const WORD_MASK : usize = WORD_SIZE - 1 ;
@@ -209,9 +210,10 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
209210
210211 let n_words = n & !WORD_MASK ;
211212 let src_misalignment = src as usize & WORD_MASK ;
212- if likely ( src_misalignment == 0 ) {
213+ if src_misalignment == 0 {
213214 copy_forward_aligned_words ( dest, src, n_words) ;
214215 } else {
216+ cold_path ( ) ;
215217 copy_forward_misaligned_words ( dest, src, n_words) ;
216218 }
217219 dest = dest. wrapping_add ( n_words) ;
@@ -327,9 +329,10 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
327329
328330 let n_words = n & !WORD_MASK ;
329331 let src_misalignment = src as usize & WORD_MASK ;
330- if likely ( src_misalignment == 0 ) {
332+ if src_misalignment == 0 {
331333 copy_backward_aligned_words ( dest, src, n_words) ;
332334 } else {
335+ cold_path ( ) ;
333336 copy_backward_misaligned_words ( dest, src, n_words) ;
334337 }
335338 dest = dest. wrapping_sub ( n_words) ;
@@ -368,7 +371,7 @@ pub unsafe fn set_bytes(mut s: *mut u8, c: u8, mut n: usize) {
368371 }
369372 }
370373
371- if likely ( n >= WORD_COPY_THRESHOLD ) {
374+ if n >= WORD_COPY_THRESHOLD {
372375 // Align s
373376 // Because of n >= 2 * WORD_SIZE, dst_misalignment < n
374377 let misalignment = ( s as usize ) . wrapping_neg ( ) & WORD_MASK ;
@@ -380,6 +383,8 @@ pub unsafe fn set_bytes(mut s: *mut u8, c: u8, mut n: usize) {
380383 set_bytes_words ( s, c, n_words) ;
381384 s = s. wrapping_add ( n_words) ;
382385 n -= n_words;
386+ } else {
387+ cold_path ( ) ;
383388 }
384389 set_bytes_bytes ( s, c, n) ;
385390}
0 commit comments