Skip to content

Commit

Permalink
Merge pull request #13 from CeleritasCelery/clippy
Browse files Browse the repository at this point in the history
Fix clippy lints
  • Loading branch information
cessen authored Feb 6, 2023
2 parents e92188e + 8e6a91e commit 5b99a71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
5 changes: 3 additions & 2 deletions benches/all.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::uninlined_format_args)]
use std::fs;

use criterion::{black_box, criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -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()
})
})
});
Expand All @@ -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);
})
});
}
Expand Down
16 changes: 5 additions & 11 deletions tests/proptests_lines_lf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,34 @@ 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
}

/// 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()
}

//===========================================================================
Expand Down

0 comments on commit 5b99a71

Please sign in to comment.