From 5656b26d7b3fa5d719e73c3ac4499db47467fb30 Mon Sep 17 00:00:00 2001 From: dailz Date: Fri, 5 Jun 2026 17:04:46 +0800 Subject: [PATCH] refactor(bench): unify line counting in get_file_info to use count_existing_lines Reuse the existing count_existing_lines() (reader.lines().count()) instead of a manual read_until loop, eliminating duplicate line-counting logic in data_gen.rs. Closes #40 --- crates/bench/src/data_gen.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/bench/src/data_gen.rs b/crates/bench/src/data_gen.rs index 770b752..8d5d675 100644 --- a/crates/bench/src/data_gen.rs +++ b/crates/bench/src/data_gen.rs @@ -21,15 +21,7 @@ pub fn ensure_test_file(path: &Path) -> std::io::Result { fn get_file_info(path: &Path) -> std::io::Result { let metadata = fs::metadata(path)?; let size_bytes = metadata.len(); - - let file = fs::File::open(path)?; - let mut reader = BufReader::new(file); - let mut line_count: u64 = 0; - let mut buf = Vec::new(); - while reader.read_until(b'\n', &mut buf)? > 0 { - line_count += 1; - buf.clear(); - } + let line_count = count_existing_lines(path)?; let avg_line_length = if line_count > 0 { size_bytes as f64 / line_count as f64