mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Bithack optimizations, why not.
It saves a branch and a (possibly inlined) function call, but it also halves the runtime.
This commit is contained in:
@@ -13,7 +13,7 @@ impl Day05 {
|
||||
fn reduce(mut data: Vec<u8>) -> usize {
|
||||
let mut dptr = 0;
|
||||
for iptr in 0..data.len() {
|
||||
if dptr > 0 && (data[iptr].eq_ignore_ascii_case(&data[dptr - 1])) && data[iptr] != data[dptr - 1] {
|
||||
if dptr > 0 && (data[iptr] ^ data[dptr - 1]) == 32 {
|
||||
dptr -= 1;
|
||||
} else {
|
||||
data[dptr] = data[iptr];
|
||||
|
||||
Reference in New Issue
Block a user