mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-28 05:21:23 +00:00
perf(table): replace while loop with simple min operation (#1747)
This commit is contained in:
parent
c27fba06f1
commit
ba9eed7742
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user