🟡 [M21] get_file_info 与 count_existing_lines 对无尾换行文件计数不一致 #40

Closed
opened 2026-06-05 11:54:14 +08:00 by dailz · 1 comment
Owner

问题

get_file_info 使用 read_until(b'\n') 手动计数;无尾换行的最后一行可能与 count_existing_linesreader.lines().count() 行为不一致。

影响

同一文件在不同函数中得到不同 line_count,会影响 avg_line_length 和 benchmark 文件信息。

位置

  • crates/bench/src/data_gen.rs:25
  • crates/bench/src/data_gen.rs:117

建议

统一行计数实现,例如都使用 reader.lines().count(),或显式处理最后一段无换行内容。

## 问题 `get_file_info` 使用 `read_until(b'\n')` 手动计数;无尾换行的最后一行可能与 `count_existing_lines` 的 `reader.lines().count()` 行为不一致。 ## 影响 同一文件在不同函数中得到不同 `line_count`,会影响 `avg_line_length` 和 benchmark 文件信息。 ## 位置 - `crates/bench/src/data_gen.rs:25` - `crates/bench/src/data_gen.rs:117` ## 建议 统一行计数实现,例如都使用 `reader.lines().count()`,或显式处理最后一段无换行内容。
Author
Owner

经审核,原 issue 描述的不一致实际不存在:read_until(b'\n') 和 lines().count() 对无尾换行文件的行为一致,均会计入最后一行。

但为减少重复代码和维护风险,已将 get_file_info 中的手动 read_until 循环替换为复用已有的 count_existing_lines(),统一行计数实现。

commit: 5656b26

经审核,原 issue 描述的不一致实际不存在:read_until(b'\n') 和 lines().count() 对无尾换行文件的行为一致,均会计入最后一行。 但为减少重复代码和维护风险,已将 get_file_info 中的手动 read_until 循环替换为复用已有的 count_existing_lines(),统一行计数实现。 commit: 5656b26
dailz closed this issue 2026-06-05 17:05:36 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/logViewer#40