@@ -20,20 +20,6 @@ const fn contains_zero_byte(x: usize) -> bool {
20
20
x. wrapping_sub ( LO_USIZE ) & !x & HI_USIZE != 0
21
21
}
22
22
23
- #[ inline]
24
- #[ cfg( target_pointer_width = "16" ) ]
25
- #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
26
- const fn repeat_byte ( b : u8 ) -> usize {
27
- ( b as usize ) << 8 | b as usize
28
- }
29
-
30
- #[ inline]
31
- #[ cfg( not( target_pointer_width = "16" ) ) ]
32
- #[ rustc_const_stable( feature = "const_memchr" , since = "1.65.0" ) ]
33
- const fn repeat_byte ( b : u8 ) -> usize {
34
- ( b as usize ) * ( usize:: MAX / 255 )
35
- }
36
-
37
23
/// Returns the first index matching the byte `x` in `text`.
38
24
#[ inline]
39
25
#[ must_use]
@@ -93,7 +79,7 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
93
79
}
94
80
95
81
// search the body of the text
96
- let repeated_x = repeat_byte ( x) ;
82
+ let repeated_x = usize :: repeat_u8 ( x) ;
97
83
while offset <= len - 2 * USIZE_BYTES {
98
84
// SAFETY: the while's predicate guarantees a distance of at least 2 * usize_bytes
99
85
// between the offset and the end of the slice.
@@ -149,7 +135,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
149
135
// Search the body of the text, make sure we don't cross min_aligned_offset.
150
136
// offset is always aligned, so just testing `>` is sufficient and avoids possible
151
137
// overflow.
152
- let repeated_x = repeat_byte ( x) ;
138
+ let repeated_x = usize :: repeat_u8 ( x) ;
153
139
let chunk_bytes = mem:: size_of :: < Chunk > ( ) ;
154
140
155
141
while offset > min_aligned_offset {
0 commit comments