@@ -16,25 +16,29 @@ const USIZE_BYTES: usize = mem::size_of::<usize>();
16
16
/// bytes where the borrow propagated all the way to the most significant
17
17
/// bit."
18
18
#[ inline]
19
+ #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
19
20
const fn contains_zero_byte ( x : usize ) -> bool {
20
21
x. wrapping_sub ( LO_USIZE ) & !x & HI_USIZE != 0
21
22
}
22
23
23
- #[ cfg( target_pointer_width = "16" ) ]
24
24
#[ inline]
25
+ #[ cfg( target_pointer_width = "16" ) ]
26
+ #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
25
27
const fn repeat_byte ( b : u8 ) -> usize {
26
28
( b as usize ) << 8 | b as usize
27
29
}
28
30
29
- #[ cfg( not( target_pointer_width = "16" ) ) ]
30
31
#[ inline]
32
+ #[ cfg( not( target_pointer_width = "16" ) ) ]
33
+ #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
31
34
const fn repeat_byte ( b : u8 ) -> usize {
32
35
( b as usize ) * ( usize:: MAX / 255 )
33
36
}
34
37
35
38
/// Returns the first index matching the byte `x` in `text`.
36
- #[ must_use]
37
39
#[ inline]
40
+ #[ must_use]
41
+ #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
38
42
pub const fn memchr ( x : u8 , text : & [ u8 ] ) -> Option < usize > {
39
43
// Fast path for small slices.
40
44
if text. len ( ) < 2 * USIZE_BYTES {
@@ -45,6 +49,7 @@ pub const fn memchr(x: u8, text: &[u8]) -> Option<usize> {
45
49
}
46
50
47
51
#[ inline]
52
+ #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
48
53
const fn memchr_naive ( x : u8 , text : & [ u8 ] ) -> Option < usize > {
49
54
let mut i = 0 ;
50
55
@@ -60,6 +65,10 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
60
65
None
61
66
}
62
67
68
+ #[ rustc_allow_const_fn_unstable( const_cmp) ]
69
+ #[ rustc_allow_const_fn_unstable( const_slice_index) ]
70
+ #[ rustc_allow_const_fn_unstable( const_align_offset) ]
71
+ #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
63
72
const fn memchr_aligned ( x : u8 , text : & [ u8 ] ) -> Option < usize > {
64
73
// Scan for a single byte value by reading two `usize` words at a time.
65
74
//
0 commit comments