From 812760233bca52e90101f8a8a0c55238af7ab156 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Mon, 6 Apr 2026 23:18:40 -0700 Subject: [PATCH] refactor(view): use Rc for sharing records in GridLayout Refactor GridLayout to use Rc for sharing records and simplify its structure. This improves performance when cloning the layout and ensures consistent data access. - Use Rc> for records in GridLayout - Update with_frozen_records and other methods to handle Rc - Simplify layout construction and sorting logic Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL) --- src/view/layout.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/view/layout.rs b/src/view/layout.rs index ce26fd6..2d5b7b5 100644 --- a/src/view/layout.rs +++ b/src/view/layout.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use crate::model::cell::{CellKey, CellValue}; use crate::model::Model; use crate::view::{Axis, View}; @@ -38,8 +40,8 @@ pub struct GridLayout { /// Categories on `Axis::None` — hidden, implicitly aggregated. pub none_cats: Vec, /// In records mode: the filtered cell list, one per row. - /// None for normal pivot views. - pub records: Option>, + /// None for normal pivot views. Rc for cheap sharing. + pub records: Option>>, } impl GridLayout { @@ -48,12 +50,11 @@ impl GridLayout { pub fn with_frozen_records( model: &Model, view: &View, - frozen_records: Option>, + frozen_records: Option>>, ) -> Self { let mut layout = Self::new(model, view); if layout.is_records_mode() { if let Some(records) = frozen_records { - // Re-build with the frozen records instead let row_items: Vec = (0..records.len()) .map(|i| AxisEntry::DataItem(vec![i.to_string()])) .collect(); @@ -183,7 +184,7 @@ impl GridLayout { row_items, col_items, none_cats, - records: Some(records), + records: Some(Rc::new(records)), } } @@ -301,7 +302,7 @@ impl GridLayout { .map(|i| AxisEntry::DataItem(vec![i.to_string()])) .collect(); self.row_items = new_row_items; - self.records = Some(new_records); + self.records = Some(Rc::new(new_records)); } }