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:
2018-12-05 22:37:22 +01:00
parent f426e7067a
commit f3d0297da5

View File

@@ -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];