From 8e6a91efc18552832bb26b76283a70ec017a7c2f Mon Sep 17 00:00:00 2001 From: Troy Hinckley Date: Sun, 5 Feb 2023 10:29:17 -0700 Subject: [PATCH] Fix clippy lints --- benches/all.rs | 5 +++-- tests/proptests_lines_lf.rs | 16 +++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/benches/all.rs b/benches/all.rs index 3919486..1a23f05 100644 --- a/benches/all.rs +++ b/benches/all.rs @@ -1,3 +1,4 @@ +#![allow(clippy::uninlined_format_args)] use std::fs; use criterion::{black_box, criterion_group, criterion_main, Criterion}; @@ -85,7 +86,7 @@ fn all(c: &mut Criterion) { } // Count the number of chars until the // char that begins at `byte_idx`. - (&text[..byte_idx]).chars().count() + text[..byte_idx].chars().count() }) }) }); @@ -112,7 +113,7 @@ fn all(c: &mut Criterion) { group.bench_function(format!("std::{}", text_name), |bench| { let idx = chars::count(text) - 1; // Minus 1 so we can unwrap below. bench.iter(|| { - black_box(text.char_indices().skip(idx).next().unwrap().0); + black_box(text.char_indices().nth(idx).unwrap().0); }) }); } diff --git a/tests/proptests_lines_lf.rs b/tests/proptests_lines_lf.rs index 52fe115..9381667 100644 --- a/tests/proptests_lines_lf.rs +++ b/tests/proptests_lines_lf.rs @@ -6,18 +6,15 @@ use str_indices::lines_lf; /// A slower, but easy-to-verify version of the library function. fn from_byte_idx_slow(text: &str, byte_idx: usize) -> usize { - let mut byte_itr = text.bytes(); - let mut i = 0; let mut line_count = 0; - while let Some(byte) = byte_itr.next() { + for (i, byte) in text.bytes().enumerate() { if i >= byte_idx { - break; + return line_count; } if byte == 0x0A { line_count += 1; } - i += 1; } line_count @@ -25,21 +22,18 @@ fn from_byte_idx_slow(text: &str, byte_idx: usize) -> usize { /// A slower, but easy-to-verify version of the library function. fn to_byte_idx_slow(text: &str, line_idx: usize) -> usize { - let mut byte_itr = text.bytes(); - let mut i = 0; let mut line_count = 0; - while let Some(byte) = byte_itr.next() { + for (i, byte) in text.bytes().enumerate() { if line_count == line_idx { - break; + return i; } if byte == 0x0A { line_count += 1; } - i += 1; } - i + text.len() } //===========================================================================