don't store match group lines twice

This commit is contained in:
Robin Appelman 2025-03-26 00:08:19 +01:00
commit 2f3e2325df
5 changed files with 10 additions and 13 deletions

View file

@ -19,11 +19,7 @@ pub struct App<'a> {
impl<'a> App<'a> { impl<'a> App<'a> {
pub fn match_lines(&self) -> usize { pub fn match_lines(&self) -> usize {
let unmatched_line_count = if self.unmatched.lines.is_empty() { let unmatched_line_count = if self.unmatched.count == 0 { 0 } else { 1 };
0
} else {
1
};
self.matches.len() + 1 + unmatched_line_count self.matches.len() + 1 + unmatched_line_count
} }
@ -45,7 +41,7 @@ impl<'a> App<'a> {
pub struct LogMatch { pub struct LogMatch {
pub result: Option<MatchResult>, pub result: Option<MatchResult>,
pub lines: Vec<usize>, pub count: usize,
pub histogram: TimeGraph, pub histogram: TimeGraph,
pub sparkline: String, pub sparkline: String,
pub all: GroupedLines, pub all: GroupedLines,
@ -60,17 +56,18 @@ impl LogMatch {
for line in lines.iter().map(|line| &all_lines[*line]) { for line in lines.iter().map(|line| &all_lines[*line]) {
histogram.add(line.time); histogram.add(line.time);
} }
let count = lines.len();
let grouped = group_lines(all_lines, lines.iter().copied()); let grouped = group_lines(all_lines, lines.iter().copied());
let sparkline = histogram.sparkline::<10>(); let sparkline = histogram.sparkline::<10>();
let all = GroupedLines { let all = GroupedLines {
sparkline: sparkline.clone(), sparkline: sparkline.clone(),
histogram: histogram.clone(), histogram: histogram.clone(),
lines: lines.clone(), lines,
}; };
LogMatch { LogMatch {
result, result,
lines, count,
histogram, histogram,
sparkline, sparkline,
grouped, grouped,
@ -116,7 +113,7 @@ impl LogMatch {
impl LogMatch { impl LogMatch {
pub fn count(&self) -> usize { pub fn count(&self) -> usize {
self.lines.len() self.count
} }
} }

View file

@ -117,7 +117,7 @@ fn main() -> MainResult {
}); });
let mut error_lines = Vec::with_capacity(32); let mut error_lines = Vec::with_capacity(32);
let mut parsed_lines = Vec::with_capacity(1024); let mut parsed_lines = Vec::with_capacity(results.len());
let mut unmatched_lines = Vec::with_capacity(256); let mut unmatched_lines = Vec::with_capacity(256);
let mut parsed_index = 0; let mut parsed_index = 0;

View file

@ -27,7 +27,7 @@ pub fn footer<'a>(app: &App<'a>, params: FooterParams<'a>) -> Table<'a> {
Table::new( Table::new(
[Row::new([ [Row::new([
Text::from(help(page)), Text::from(help(page)),
Text::from(format!("{} unmatched items", app.unmatched.lines.len())), Text::from(format!("{} unmatched items", app.unmatched.count())),
Text::from(format!("{} parse errors", app.error_count)), Text::from(format!("{} parse errors", app.error_count)),
])], ])],
widths, widths,

View file

@ -30,7 +30,7 @@ pub fn match_list<'a>(app: &'a App<'a>, filter: &Filter) -> ScrollbarTable<'a> {
]; ];
let all = log_row(&app.all, app, "All lines"); let all = log_row(&app.all, app, "All lines");
let unmatched = if app.unmatched.lines.is_empty() { let unmatched = if app.unmatched.count() == 0 {
Either::Right(empty()) Either::Right(empty())
} else { } else {
Either::Left(once(log_row(&app.unmatched, app, "Unmatched lines"))) Either::Left(once(log_row(&app.unmatched, app, "Unmatched lines")))

View file

@ -38,7 +38,7 @@ pub fn grouped_lines<'a>(
Text::from(""), Text::from(""),
Text::from(""), Text::from(""),
Text::from(log_match.sparkline.as_str()), Text::from(log_match.sparkline.as_str()),
Text::from(log_match.lines.len().to_string()), Text::from(log_match.count().to_string()),
])) ]))
.chain( .chain(
grouped grouped