🎉 Improve performance reducing unnecessary calls to set-objects

This commit is contained in:
Alejandro Alonso 2025-03-25 16:21:03 +01:00
parent e012046f62
commit 7728d5b317
20 changed files with 360 additions and 180 deletions

View file

@ -8,13 +8,15 @@ mod render;
mod shapes;
mod state;
mod utils;
mod uuid;
mod view;
mod wasm;
use crate::mem::SerializableResult;
use crate::shapes::{BoolType, ConstraintH, ConstraintV, TransformEntry, Type};
use crate::utils::uuid_from_u32_quartet;
use crate::uuid::Uuid;
use indexmap::IndexSet;
use state::State;
pub(crate) static mut STATE: Option<Box<State>> = None;
@ -201,6 +203,28 @@ pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
});
}
#[no_mangle]
pub extern "C" fn set_children() {
let bytes = mem::bytes();
let entries: IndexSet<Uuid> = bytes
.chunks(size_of::<<Uuid as SerializableResult>::BytesType>())
.map(|data| Uuid::from_bytes(data.try_into().unwrap()))
.collect();
let mut deleted = IndexSet::new();
with_current_shape!(state, |shape: &mut Shape| {
(_, deleted) = shape.compute_children_differences(&entries);
shape.children = entries.clone();
});
with_state!(state, {
for id in deleted {
state.delete_shape(id);
}
});
}
#[no_mangle]
pub extern "C" fn clear_shape_children() {
with_current_shape!(state, |shape: &mut Shape| {
@ -621,6 +645,13 @@ pub extern "C" fn clear_shape_shadows() {
});
}
#[no_mangle]
pub extern "C" fn update_shape_tiles() {
with_state!(state, {
state.update_tile_for_current_shape();
});
}
#[no_mangle]
pub extern "C" fn set_flex_layout_data(
dir: u8,