File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ impl<'a> Iterator for ToCityTemperatures<'a> {
32
32
let chunk = & self . chunk [ self . position ..] ;
33
33
34
34
// Since city names have at least 3 characters, we can skip the first 3 bytes.
35
- let city_len = 3 + chunk[ 3 ..] . find_byte_index ( b';' ) ;
35
+ let city_len = 3 + chunk[ 3 ..] . find_byte ( b';' ) . unwrap ( ) ;
36
36
let city = & chunk[ ..city_len] ;
37
37
38
38
// We don't need to check for the length of the temperature by finding the next line break.
Original file line number Diff line number Diff line change 1
1
use std:: simd:: { cmp:: SimdPartialEq , u8x32} ;
2
2
3
+ type Result < T > = std:: result:: Result < T , ( ) > ;
4
+
3
5
pub trait FindByte {
4
- fn find_byte_index ( & self , byte : u8 ) -> usize ;
6
+ fn find_byte ( & self , byte : u8 ) -> Result < usize > ;
5
7
}
6
8
7
9
impl FindByte for [ u8 ] {
8
10
#[ inline( always) ]
9
- fn find_byte_index ( & self , byte : u8 ) -> usize {
11
+ fn find_byte ( & self , byte : u8 ) -> Result < usize > {
10
12
let simd_width = 32 ; // 256-bit wide SIMD register
11
13
12
14
for ( i, chunk) in self . chunks_exact ( simd_width) . enumerate ( ) {
@@ -24,7 +26,7 @@ impl FindByte for [u8] {
24
26
let mask = masks[ j] ;
25
27
if mask != 0 {
26
28
// Calculate the position of the match
27
- return i * simd_width + j * 8 + mask. trailing_zeros ( ) as usize ;
29
+ return Ok ( i * simd_width + j * 8 + mask. trailing_zeros ( ) as usize ) ;
28
30
}
29
31
}
30
32
}
@@ -34,6 +36,6 @@ impl FindByte for [u8] {
34
36
. remainder ( )
35
37
. iter ( )
36
38
. position ( |& c| c == byte)
37
- . unwrap ( )
39
+ . ok_or ( ( ) )
38
40
}
39
41
}
You can’t perform that action at this time.
0 commit comments