perf(table): replace while loop with simple min operation (#1747)

This commit is contained in:
EdJoPaTo 2025-04-02 23:55:47 +02:00 committed by GitHub
parent c27fba06f1
commit ba9eed7742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -910,6 +910,11 @@ impl Table<'_> {
fn visible_rows(&self, state: &TableState, area: Rect) -> (usize, usize) {
let last_row = self.rows.len().saturating_sub(1);
let mut start = state.offset.min(last_row);
if let Some(selected) = state.selected {
start = start.min(selected);
}
let mut end = start;
let mut height = 0;
@ -933,16 +938,6 @@ impl Table<'_> {
start += 1;
}
}
// scroll up until the selected row is visible
while selected < start {
start -= 1;
height = height.saturating_add(self.rows[start].height_with_margin());
while height > area.height {
end -= 1;
height = height.saturating_sub(self.rows[end].height_with_margin());
}
}
}
// Include a partial row if there is space