File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ fn search(target: u64, v: &[u64]) -> bool {
2121
2222#[ aoc( day7, part1) ]
2323pub fn part1 ( s : & str ) -> u64 {
24+ unsafe { part1_inner ( s) }
25+ }
26+
27+ unsafe fn part1_inner ( s : & str ) -> u64 {
2428 let s = s. as_bytes ( ) ;
2529
2630 let mut sum = 0 ;
@@ -29,23 +33,23 @@ pub fn part1(s: &str) -> u64 {
2933 let mut v = Vec :: new ( ) ;
3034 while i < s. len ( ) {
3135 let mut target: u64 = 0 ;
32- while s [ i ] != b':' {
36+ while * s . get_unchecked ( i ) != b':' {
3337 target *= 10 ;
34- target += ( s [ i ] - b'0' ) as u64 ;
38+ target += ( * s . get_unchecked ( i ) - b'0' ) as u64 ;
3539 i += 1 ;
3640 }
3741 i += 2 ;
3842
3943 let mut num = 0 ;
40- while s [ i ] != b'\n' {
44+ while * s . get_unchecked ( i ) != b'\n' {
4145 num *= 10 ;
42- num += ( s [ i ] - b'0' ) as u64 ;
46+ num += ( * s . get_unchecked ( i ) - b'0' ) as u64 ;
4347 i += 1 ;
44- if !s[ i ] . is_ascii_digit ( ) {
48+ if !s. get_unchecked ( i ) . is_ascii_digit ( ) {
4549 v. push ( num) ;
4650 num = 0 ;
4751 i += 1 ;
48- if s [ i - 1 ] == b'\n' {
52+ if * s . get_unchecked ( i - 1 ) == b'\n' {
4953 break ;
5054 }
5155 }
You can’t perform that action at this time.
0 commit comments