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:
@ -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<String>,
|
||||
/// In records mode: the filtered cell list, one per row.
|
||||
/// None for normal pivot views.
|
||||
pub records: Option<Vec<(CellKey, CellValue)>>,
|
||||
/// None for normal pivot views. Rc for cheap sharing.
|
||||
pub records: Option<Rc<Vec<(CellKey, CellValue)>>>,
|
||||
}
|
||||
|
||||
impl GridLayout {
|
||||
@ -48,12 +50,11 @@ impl GridLayout {
|
||||
pub fn with_frozen_records(
|
||||
model: &Model,
|
||||
view: &View,
|
||||
frozen_records: Option<Vec<(CellKey, CellValue)>>,
|
||||
frozen_records: Option<Rc<Vec<(CellKey, CellValue)>>>,
|
||||
) -> 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<AxisEntry> = (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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user