From d1cac0baf011ad1cd981296c52a1a05778d1cf65 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Thu, 5 Oct 2023 11:06:26 +0200 Subject: [PATCH] clippy fix. --- src/esa.rs | 4 +--- src/lib.rs | 2 +- src/sais.rs | 8 ++------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/esa.rs b/src/esa.rs index d787e9c..012c545 100644 --- a/src/esa.rs +++ b/src/esa.rs @@ -29,9 +29,7 @@ fn suffixtree( h += 1; } right[i] = h; - if h > 0 { - h -= 1; - } + h = h.saturating_sub(1); } // H = l diff --git a/src/lib.rs b/src/lib.rs index 58dc58f..c4bb21a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -378,6 +378,6 @@ mod rs_tests { #[test] fn test_out_of_bounds_bug() { let string = "banana$band$$"; - suffix_rs(&string).unwrap(); + suffix_rs(string).unwrap(); } } diff --git a/src/sais.rs b/src/sais.rs index b69fa7f..ab8ea1b 100644 --- a/src/sais.rs +++ b/src/sais.rs @@ -291,9 +291,7 @@ fn suffixsort( if suffix_array[i] != 0 { suffix_array[ra_index + j] = suffix_array[i] - 1; // XXX: Bug underflow caught by Rust yeah (well cpp used i32) - if j > 0 { - j -= 1; - } + j = j.saturating_sub(1); } } // XXX: Could call transmute on SA to avoid allocation. @@ -318,9 +316,7 @@ fn suffixsort( } else if c_index != 0 { suffix_array[ra_index + j] = i + 1; c_index = 0; - if j > 0 { - j -= 1; /* get p1 */ - } + j = j.saturating_sub(1); } c1 = c0; }