mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
perf(table): avoid extra allocations when rendering Table
(#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.
This commit is contained in:
parent
efef0d0dc0
commit
be3eb75ea5
2 changed files with 2 additions and 2 deletions
|
@ -134,7 +134,7 @@ impl<'a> Cell<'a> {
|
||||||
impl Cell<'_> {
|
impl Cell<'_> {
|
||||||
pub(crate) fn render(&self, area: Rect, buf: &mut Buffer) {
|
pub(crate) fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||||
buf.set_style(area, self.style);
|
buf.set_style(area, self.style);
|
||||||
self.content.clone().render(area, buf);
|
self.content.render_ref(area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -722,7 +722,7 @@ impl Table<'_> {
|
||||||
..row_area
|
..row_area
|
||||||
};
|
};
|
||||||
buf.set_style(selection_area, row.style);
|
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()) {
|
for ((x, width), cell) in columns_widths.iter().zip(row.cells.iter()) {
|
||||||
cell.render(
|
cell.render(
|
||||||
|
|
Loading…
Reference in a new issue