Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Sep 14, 2023
1 parent 7456f7a commit ca3413d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Histogram {
}

fn num_token_occurances(&self, token: Token) -> u32 {
self.token_occurances[token.0 as usize].len(&self.pool) as u32
self.token_occurances[token.0 as usize].len(&self.pool)
}

fn populate(&mut self, file: &[Token]) {
Expand Down
2 changes: 1 addition & 1 deletion src/histogram/list_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl ListPool {
fn free(&mut self, block: usize, sclass: SizeClass) {
let sclass = sclass as usize;
// Insert the block on the free list which is a single linked list.
self.data[block] = self.free[sclass] as u32;
self.data[block] = self.free[sclass];
self.free[sclass] = block as u32
}

Expand Down
2 changes: 1 addition & 1 deletion src/myers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Drop for Myers {

impl Myers {
fn new(len1: usize, len2: usize) -> Self {
let ndiags = len1 + len2 as usize + 3;
let ndiags = len1 + len2 + 3;
let kvec = Box::leak(vec![0; 2 * ndiags + 2].into_boxed_slice());
let kforward = NonNull::from(&mut kvec[len2 + 1]);
let kbackward = NonNull::from(&mut kvec[ndiags + len2 + 1]);
Expand Down
4 changes: 2 additions & 2 deletions src/myers/middle_snake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<const BACK: bool> MiddleSnakeSearch<BACK> {
pub fn pos_at_diagonal(&self, diagonal: i32) -> (i32, i32) {
self.bounds_check(diagonal);
let token_idx1 = unsafe { self.kvec.as_ptr().offset(diagonal as isize).read() };
let token_idx2 = (token_idx1 as i32 - diagonal) as i32;
let token_idx2 = token_idx1 - diagonal;
(token_idx1, token_idx2)
}

Expand Down Expand Up @@ -110,7 +110,7 @@ impl<const BACK: bool> MiddleSnakeSearch<BACK> {
self.x_pos_at_diagonal(k + 1)
};

let mut token_idx2 = (token_idx1 as i32 - k) as i32;
let mut token_idx2 = token_idx1 - k;
let off = if BACK {
if token_idx1 > 0 && token_idx2 > 0 {
let tokens1 = &file1.tokens[..token_idx1 as usize];
Expand Down
19 changes: 9 additions & 10 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,15 @@ fn hand_checked_udiffs() {
for algorithm in Algorithm::ALL {
println!("{algorithm:?}");
let test_dir = project_root().join("tests");
for file in ["helix_syntax.rs"] {
let path_before = test_dir.join(format!("{file}.before"));
let path_after = test_dir.join(format!("{file}.after"));
let path_diff = test_dir.join(format!("{file}.{algorithm:?}.diff"));
let before = read_to_string(path_before).unwrap();
let after = read_to_string(path_after).unwrap();
let input = InternedInput::new(&*before, &*after);
let diff = diff(algorithm, &input, UnifiedDiffBuilder::new(&input));
expect_file![path_diff].assert_eq(&diff);
}
let file = "helix_syntax.rs";
let path_before = test_dir.join(format!("{file}.before"));
let path_after = test_dir.join(format!("{file}.after"));
let path_diff = test_dir.join(format!("{file}.{algorithm:?}.diff"));
let before = read_to_string(path_before).unwrap();
let after = read_to_string(path_after).unwrap();
let input = InternedInput::new(&*before, &*after);
let diff = diff(algorithm, &input, UnifiedDiffBuilder::new(&input));
expect_file![path_diff].assert_eq(&diff);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ pub fn strip_common_postfix(file1: &mut &[Token], file2: &mut &[Token]) -> u32 {
}

pub fn sqrt(val: usize) -> u32 {
let nbits = (usize::BITS as u32 - val.leading_zeros()) / 2;
let nbits = (usize::BITS - val.leading_zeros()) / 2;
1 << nbits
}

0 comments on commit ca3413d

Please sign in to comment.