1
0
Fork 0

Optimized integer parsing in day 7 part 2

This commit is contained in:
Ishan Jain 2022-12-07 17:52:55 +05:30
parent 6d92264741
commit 4073f69c84
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27
2 changed files with 5 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
/target
go.mod
go.sum
test.go
*.go
test

View File

@ -48,8 +48,10 @@ fn solution(input: impl Iterator<Item = &'static str>) -> u32 {
},
_ => {
let (size, _) = line.split_once(' ').unwrap();
let size = size.parse::<u32>().unwrap();
let size = line
.bytes()
.take_while(|&c| c != b' ')
.fold(0u32, |a, x| a * 10 + (x - b'0') as u32);
current_folder_size += size;
}
}