mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Scripts: a command no longer copies the empty-path closed settings
Each command a script ran copied the set of empty paths the script had closed into the command's style trail, so a script that closed N empty paths copied up to N entries per command. The trail now shares the set through an `Arc`, and drops its share when the command's steps end, so a later change to the set does not copy it either. Settings that end after a kept command are dropped only when one actually ends.
This commit is contained in:
1 parent
eba5ecbdfc
commit
52ae980326
3 files changed
+24
-9
No files matched your search
@@ -205,8 +205,9 @@ pub(super) struct State {
|
||||
/// ([`flush`]).
|
||||
pending: RefCell<Option<(Item, Vec<vectorcraft_geom::path::SubPath>)>>,
|
||||
/// The paths with no points, by document uid, revert count and id, that a script set `closed`
|
||||
/// on: the points `setEntirePath` gives them later make a closed path.
|
||||
pub(super) closed_empty: RefCell<HashSet<(u64, u64, NodeId)>>,
|
||||
/// on: the points `setEntirePath` gives them later make a closed path. A command's steps share
|
||||
/// the set without copying it ([`super::StyleTrail`]).
|
||||
pub(super) closed_empty: RefCell<Arc<HashSet<(u64, u64, NodeId)>>>,
|
||||
/// The index of the first point of each subpath of the path whose points the run read last,
|
||||
/// and what they were counted from ([`paths`]).
|
||||
point_starts: RefCell<Option<(paths::Counted, Rc<Vec<usize>>)>>,
|
||||
|
||||
@@ -256,7 +256,10 @@ fn edit_points<T>(h: &super::Host, item: Item, f: impl FnOnce(&mut Vec<SubPath>)
|
||||
let gained = |gained: bool| {
|
||||
if gained {
|
||||
let key = closed_key(h, item);
|
||||
h.dom.closed_empty.borrow_mut().remove(&key);
|
||||
let mut held = h.dom.closed_empty.borrow_mut();
|
||||
if held.contains(&key) {
|
||||
Arc::make_mut(&mut held).remove(&key);
|
||||
}
|
||||
}
|
||||
};
|
||||
let mut f = Some(f);
|
||||
@@ -305,7 +308,7 @@ fn closed_key(h: &super::Host, item: Item) -> (u64, u64, NodeId) {
|
||||
/// Drops empty-path closed settings after a kept command gives a path points or removes it.
|
||||
pub(super) fn forget_closed_empty(h: &super::Host) {
|
||||
let s = h.session.borrow();
|
||||
h.dom.closed_empty.borrow_mut().retain(|(uid, reverts, id)| {
|
||||
let keep = |(uid, reverts, id): &(u64, u64, NodeId)| {
|
||||
!s.script_style_trail.paths_with_points.contains(&(*uid, *reverts, *id))
|
||||
&& s.documents()
|
||||
.iter()
|
||||
@@ -313,7 +316,12 @@ pub(super) fn forget_closed_empty(h: &super::Host) {
|
||||
.and_then(|st| st.doc.node(*id))
|
||||
.and_then(|n| n.path_data())
|
||||
.is_some_and(|pd| pd.subpaths.is_empty())
|
||||
});
|
||||
};
|
||||
let mut held = h.dom.closed_empty.borrow_mut();
|
||||
// The set is copied only when another holder shares it and a setting ends.
|
||||
if !held.iter().all(keep) {
|
||||
Arc::make_mut(&mut held).retain(keep);
|
||||
}
|
||||
}
|
||||
|
||||
/// Drops the [`starts`] that [`super::State`] keeps of waiting point changes, which a change can
|
||||
@@ -786,6 +794,7 @@ fn path_set_closed(h: &super::Host, a: &[Data]) -> Answer {
|
||||
with_doc(h, item.doc, |_, st| refuse_path_edit(h, st, item.id))?;
|
||||
let key = closed_key(h, item);
|
||||
let mut held = h.dom.closed_empty.borrow_mut();
|
||||
let held = Arc::make_mut(&mut held);
|
||||
if closed {
|
||||
held.insert(key);
|
||||
} else {
|
||||
|
||||
@@ -1432,7 +1432,11 @@ fn command_crossing(host: &Host, id: &str, params: &Value, cross: bool) -> std::
|
||||
let before = dom::before_command(host, id);
|
||||
let r = {
|
||||
let mut s = session.borrow_mut();
|
||||
step(&mut s, host, id, params)
|
||||
let r = step(&mut s, host, id, params);
|
||||
// The steps are done with the empty-path closed settings, so the object model can change
|
||||
// them again without copying them.
|
||||
s.script_style_trail.closed_empty = Arc::default();
|
||||
r
|
||||
};
|
||||
// The resource names a failed command's steps compared are still charged, before its error is
|
||||
// given.
|
||||
@@ -1511,14 +1515,15 @@ pub(crate) struct StyleTrail {
|
||||
pub(in crate::script) resources_gone: std::collections::HashSet<(u64, dom::ResourceKind, String)>,
|
||||
/// The resource names the steps compared, charged to the run with the check that follows.
|
||||
pub(crate) resources_scanned: u64,
|
||||
closed_empty: std::collections::HashSet<(u64, u64, NodeId)>,
|
||||
/// The object model's empty-path closed settings, shared with it while the steps run.
|
||||
closed_empty: Arc<std::collections::HashSet<(u64, u64, NodeId)>>,
|
||||
pub(in crate::script) paths_with_points: std::collections::HashSet<(u64, u64, NodeId)>,
|
||||
}
|
||||
|
||||
impl StyleTrail {
|
||||
/// A trail that starts from the documents' style lists now, and from the documents themselves
|
||||
/// when `watch_resources`.
|
||||
fn start(s: &Session, watch_resources: bool, closed_empty: std::collections::HashSet<(u64, u64, NodeId)>) -> Self {
|
||||
fn start(s: &Session, watch_resources: bool, closed_empty: Arc<std::collections::HashSet<(u64, u64, NodeId)>>) -> Self {
|
||||
let lists = s.docs.iter().map(|st| (st.uid, st.reverts, st.doc.char_styles.clone(), st.doc.para_styles.clone())).collect();
|
||||
let docs = if watch_resources { s.docs.iter().map(|st| (st.uid, st.doc.clone())).collect() } else { Vec::new() };
|
||||
StyleTrail { lists, docs, watch_resources, closed_empty, ..Default::default() }
|
||||
@@ -1531,7 +1536,7 @@ impl StyleTrail {
|
||||
/// document's lists, however many steps change them.
|
||||
pub(crate) fn note_style_lists(s: &mut Session) {
|
||||
let trail = &mut s.script_style_trail;
|
||||
for &(uid, reverts, id) in &trail.closed_empty {
|
||||
for &(uid, reverts, id) in trail.closed_empty.iter() {
|
||||
if s.docs
|
||||
.iter()
|
||||
.find(|st| st.uid == uid && st.reverts == reverts)
|
||||
|
||||
Reference in new issue
Block a user