3
3
// We use this mainly to skip repeated `/`. If there is only one slash, `memrnchr` performs the same
4
4
// as a naive version (e.g. `rposition`). However, it is much faster in pathological cases.
5
5
6
- const LO_U64 : u64 = 0x0101010101010101 ;
7
- const HI_U64 : u64 = 0x8080808080808080 ;
8
-
9
- // use truncation
10
- const LO_USIZE : usize = LO_U64 as usize ;
11
- const HI_USIZE : usize = HI_U64 as usize ;
12
-
13
6
#[ cfg( target_pointer_width = "32" ) ]
14
7
const USIZE_BYTES : usize = 4 ;
15
8
#[ cfg( target_pointer_width = "64" ) ]
@@ -49,10 +42,8 @@ pub fn memrnchr(x: u8, text: &[u8]) -> Option<usize> {
49
42
let u = * ( ptr. offset ( offset as isize - 2 * USIZE_BYTES as isize ) as * const usize ) ;
50
43
let v = * ( ptr. offset ( offset as isize - USIZE_BYTES as isize ) as * const usize ) ;
51
44
52
- // break if there is a matching byte
53
- let zu = contains_zero_byte ( u ^ repeated_x) ;
54
- let zv = contains_zero_byte ( v ^ repeated_x) ;
55
- if !zu || !zv {
45
+ // break if there is no matching byte
46
+ if u & repeated_x != usize:: max_value ( ) || v & repeated_x != usize:: max_value ( ) {
56
47
break ;
57
48
}
58
49
}
@@ -63,18 +54,6 @@ pub fn memrnchr(x: u8, text: &[u8]) -> Option<usize> {
63
54
text[ ..offset] . iter ( ) . rposition ( |elt| * elt != x)
64
55
}
65
56
66
- /// Return `true` if `x` contains any zero byte.
67
- ///
68
- /// From *Matters Computational*, J. Arndt
69
- ///
70
- /// "The idea is to subtract one from each of the bytes and then look for
71
- /// bytes where the borrow propagated all the way to the most significant
72
- /// bit."
73
- #[ inline]
74
- fn contains_zero_byte ( x : usize ) -> bool {
75
- x. wrapping_sub ( LO_USIZE ) & !x & HI_USIZE != 0
76
- }
77
-
78
57
#[ cfg( target_pointer_width = "32" ) ]
79
58
#[ inline]
80
59
fn repeat_byte ( b : u8 ) -> usize {
0 commit comments