From be3eb75ea58127caad6696a21d794f5f99e0dfd6 Mon Sep 17 00:00:00 2001 From: Tayfun Bocek Date: Fri, 26 Jul 2024 18:48:29 +0000 Subject: [PATCH] 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>` inside `Text`. Also avoids an allocation when rendering the highlight symbol if it contains an owned value. --- src/widgets/table/cell.rs | 2 +- src/widgets/table/table.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/table/cell.rs b/src/widgets/table/cell.rs index f51a82f4..abeecb13 100644 --- a/src/widgets/table/cell.rs +++ b/src/widgets/table/cell.rs @@ -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); } } diff --git a/src/widgets/table/table.rs b/src/widgets/table/table.rs index 2c046784..86504049 100644 --- a/src/widgets/table/table.rs +++ b/src/widgets/table/table.rs @@ -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(