Skip to content

Commit

Permalink
perf(table): avoid extra allocations when rendering Table (ratatui#…
Browse files Browse the repository at this point in the history
…1242)

When rendering a `Table` the `Text` stored inside of a `Cell` gets
cloned before rendering. This removes the clone and uses `WidgetRef`
instead, saving us from allocating a `Vec<Line<'_>>` inside `Text`. Also
avoids an allocation when rendering the highlight symbol if it contains
an owned value.
  • Loading branch information
airblast-dev authored and joshka committed Oct 14, 2024
1 parent 9b4c2ce commit ef15cf3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/widgets/table/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a> Cell<'a> {
impl Cell<'_> {
pub(crate) fn render(&self, area: Rect, buf: &mut Buffer) {
buf.set_style(area, self.style);
self.content.clone().render(area, buf);
self.content.render_ref(area, buf);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/table/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ impl Table<'_> {
..row_area
};
buf.set_style(selection_area, row.style);
highlight_symbol.clone().render(selection_area, buf);
highlight_symbol.render_ref(selection_area, buf);
};
for ((x, width), cell) in columns_widths.iter().zip(row.cells.iter()) {
cell.render(
Expand Down

0 comments on commit ef15cf3

Please sign in to comment.