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<Vec<(CellKey, CellValue)>> 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)
This commit is contained in:
Edward Langley
2026-04-06 23:18:40 -07:00
parent a17802e07d
commit 812760233b

View File

@ -1,3 +1,5 @@
use std::rc::Rc;
use crate::model::cell::{CellKey, CellValue}; use crate::model::cell::{CellKey, CellValue};
use crate::model::Model; use crate::model::Model;
use crate::view::{Axis, View}; use crate::view::{Axis, View};
@ -38,8 +40,8 @@ pub struct GridLayout {
/// Categories on `Axis::None` — hidden, implicitly aggregated. /// Categories on `Axis::None` — hidden, implicitly aggregated.
pub none_cats: Vec<String>, pub none_cats: Vec<String>,
/// In records mode: the filtered cell list, one per row. /// In records mode: the filtered cell list, one per row.
/// None for normal pivot views. /// None for normal pivot views. Rc for cheap sharing.
pub records: Option<Vec<(CellKey, CellValue)>>, pub records: Option<Rc<Vec<(CellKey, CellValue)>>>,
} }
impl GridLayout { impl GridLayout {
@ -48,12 +50,11 @@ impl GridLayout {
pub fn with_frozen_records( pub fn with_frozen_records(
model: &Model, model: &Model,
view: &View, view: &View,
frozen_records: Option<Vec<(CellKey, CellValue)>>, frozen_records: Option<Rc<Vec<(CellKey, CellValue)>>>,
) -> Self { ) -> Self {
let mut layout = Self::new(model, view); let mut layout = Self::new(model, view);
if layout.is_records_mode() { if layout.is_records_mode() {
if let Some(records) = frozen_records { if let Some(records) = frozen_records {
// Re-build with the frozen records instead
let row_items: Vec<AxisEntry> = (0..records.len()) let row_items: Vec<AxisEntry> = (0..records.len())
.map(|i| AxisEntry::DataItem(vec![i.to_string()])) .map(|i| AxisEntry::DataItem(vec![i.to_string()]))
.collect(); .collect();
@ -183,7 +184,7 @@ impl GridLayout {
row_items, row_items,
col_items, col_items,
none_cats, none_cats,
records: Some(records), records: Some(Rc::new(records)),
} }
} }
@ -301,7 +302,7 @@ impl GridLayout {
.map(|i| AxisEntry::DataItem(vec![i.to_string()])) .map(|i| AxisEntry::DataItem(vec![i.to_string()]))
.collect(); .collect();
self.row_items = new_row_items; self.row_items = new_row_items;
self.records = Some(new_records); self.records = Some(Rc::new(new_records));
} }
} }