Merge pull request #6449 from penpot/superalex-add-shapes-buffer

🎉 Add shapes buffer to improve memory allocation
This commit is contained in:
Aitor Moreno 2025-05-12 10:23:34 +02:00 committed by GitHub
commit 69062f03ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 122 additions and 36 deletions

View file

@ -16,7 +16,7 @@ use crate::uuid::Uuid;
fn propagate_children(
shape: &Shape,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
parent_bounds_before: &Bounds,
parent_bounds_after: &Bounds,
transform: Matrix,
@ -83,7 +83,7 @@ fn propagate_children(
fn calculate_group_bounds(
shape: &Shape,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> Option<Bounds> {
@ -303,19 +303,20 @@ mod tests {
#[test]
fn test_propagate_shape() {
let mut shapes = HashMap::<Uuid, Shape>::new();
let mut shapes = HashMap::<Uuid, &mut Shape>::new();
let child_id = Uuid::new_v4();
let mut child = Shape::new(child_id);
child.set_selrect(3.0, 3.0, 2.0, 2.0);
shapes.insert(child_id, child);
shapes.insert(child_id, &mut child);
let parent_id = Uuid::new_v4();
let mut parent = Shape::new(parent_id);
parent.set_shape_type(Type::Group(Group::default()));
parent.add_child(child_id);
parent.set_selrect(1.0, 1.0, 5.0, 5.0);
shapes.insert(parent_id, parent.clone());
let mut parent_clone = parent.clone();
shapes.insert(parent_id, &mut parent_clone);
let mut transform = Matrix::scale((2.0, 1.5));
let x = parent.selrect.x();
@ -341,17 +342,17 @@ mod tests {
#[test]
fn test_group_bounds() {
let mut shapes = HashMap::<Uuid, Shape>::new();
let mut shapes = HashMap::<Uuid, &mut Shape>::new();
let child1_id = Uuid::new_v4();
let mut child1 = Shape::new(child1_id);
child1.set_selrect(3.0, 3.0, 2.0, 2.0);
shapes.insert(child1_id, child1);
shapes.insert(child1_id, &mut child1);
let child2_id = Uuid::new_v4();
let mut child2 = Shape::new(child2_id);
child2.set_selrect(0.0, 0.0, 1.0, 1.0);
shapes.insert(child2_id, child2);
shapes.insert(child2_id, &mut child2);
let parent_id = Uuid::new_v4();
let mut parent = Shape::new(parent_id);
@ -359,7 +360,8 @@ mod tests {
parent.add_child(child1_id);
parent.add_child(child2_id);
parent.set_selrect(0.0, 0.0, 3.0, 3.0);
shapes.insert(parent_id, parent.clone());
let mut parent_clone = parent.clone();
shapes.insert(parent_id, &mut parent_clone);
let bounds =
calculate_group_bounds(&parent, &shapes, &HashMap::new(), &HashMap::new()).unwrap();

View file

@ -178,7 +178,7 @@ fn initialize_tracks(
layout_bounds: &Bounds,
layout_axis: &LayoutAxis,
flex_data: &FlexData,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> Vec<TrackData> {
@ -420,7 +420,7 @@ fn calculate_track_data(
layout_data: &LayoutData,
flex_data: &FlexData,
layout_bounds: &Bounds,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> Vec<TrackData> {
@ -551,7 +551,7 @@ pub fn reflow_flex_layout(
shape: &Shape,
layout_data: &LayoutData,
flex_data: &FlexData,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &mut HashMap<Uuid, Bounds>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> VecDeque<Modifier> {

View file

@ -40,7 +40,7 @@ fn calculate_tracks(
grid_data: &GridData,
layout_bounds: &Bounds,
cells: &Vec<GridCell>,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
) -> Vec<TrackData> {
let layout_size = if is_column {
@ -105,7 +105,7 @@ fn set_auto_base_size(
column: bool,
tracks: &mut Vec<TrackData>,
cells: &Vec<GridCell>,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
) {
for cell in cells {
@ -156,7 +156,7 @@ fn set_auto_multi_span(
column: bool,
tracks: &mut Vec<TrackData>,
cells: &Vec<GridCell>,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
) {
// Remove groups with flex (will be set in flex_multi_span)
@ -230,7 +230,7 @@ fn set_flex_multi_span(
column: bool,
tracks: &mut Vec<TrackData>,
cells: &Vec<GridCell>,
shapes: &HashMap<Uuid, Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
) {
// Remove groups without flex
@ -509,7 +509,7 @@ fn cell_bounds(
fn create_cell_data<'a>(
layout_bounds: &Bounds,
children: &IndexSet<Uuid>,
shapes: &'a HashMap<Uuid, Shape>,
shapes: &'a HashMap<Uuid, &mut Shape>,
cells: &Vec<GridCell>,
column_tracks: &Vec<TrackData>,
row_tracks: &Vec<TrackData>,
@ -618,7 +618,7 @@ pub fn reflow_grid_layout<'a>(
shape: &Shape,
layout_data: &LayoutData,
grid_data: &GridData,
shapes: &'a HashMap<Uuid, Shape>,
shapes: &'a HashMap<Uuid, &mut Shape>,
bounds: &mut HashMap<Uuid, Bounds>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> VecDeque<Modifier> {