From 308fbc503f679b32f8db6f12869b5cec7b428455 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Wed, 16 Dec 2020 20:05:08 +0100 Subject: [PATCH] Fix misc clippy warnings Why does it want me to use bytecount? It's not even faster --- 2020/Cargo.toml | 1 + 2020/src/day11.rs | 6 ++++-- 2020/src/day14.rs | 2 +- 2020/src/day16.rs | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/2020/Cargo.toml b/2020/Cargo.toml index 9b5446c..f9fd536 100644 --- a/2020/Cargo.toml +++ b/2020/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Bert Peters "] edition = "2018" [dependencies] +bytecount = "0.6" clap = "3.0.0-beta.2" itertools = "0.9" num-integer = "0.1" diff --git a/2020/src/day11.rs b/2020/src/day11.rs index 317f687..9ca8bc9 100644 --- a/2020/src/day11.rs +++ b/2020/src/day11.rs @@ -1,6 +1,8 @@ use std::io::Read; use std::mem::swap; +use bytecount::naive_count_32; + use crate::common::read_char_grid; use crate::Solution; @@ -9,12 +11,12 @@ fn neighbours(grid: &[Vec], r: usize, c: usize) -> usize { if r > 0 { let range = c.saturating_sub(1)..grid[r - 1].len().min(c + 2); - n += grid[r - 1][range].iter().filter(|&&s| s == b'#').count(); + n += naive_count_32(&grid[r - 1][range], b'#'); } if r < grid.len() - 1 { let range = c.saturating_sub(1)..grid[r + 1].len().min(c + 2); - n += grid[r + 1][range].iter().filter(|&&s| s == b'#').count(); + n += naive_count_32(&grid[r + 1][range], b'#'); } if c > 0 && grid[r][c - 1] == b'#' { diff --git a/2020/src/day14.rs b/2020/src/day14.rs index acbae62..1f28b63 100644 --- a/2020/src/day14.rs +++ b/2020/src/day14.rs @@ -65,7 +65,7 @@ fn x_mask_permutations(mut x_mask: u64, permutations: &mut Vec) { while x_mask > 0 { let trailing = x_mask.trailing_zeros(); - let bit = 1 << trailing + offset; + let bit = 1 << (trailing + offset); x_mask >>= trailing + 1; offset += trailing + 1; diff --git a/2020/src/day16.rs b/2020/src/day16.rs index 9a7ce3e..edd508f 100644 --- a/2020/src/day16.rs +++ b/2020/src/day16.rs @@ -15,6 +15,8 @@ fn split_nums<'a>(s: &'a str) -> impl Iterator + 'a { }) } +// Clippy allow here because this type is used exactly once +#[allow(clippy::type_complexity)] fn read_input(input: &mut dyn Read) -> (HashMap>>, Vec>) { let mut lines = Lines::new(input).filter(|s| !s.is_empty());