Skip to content

Commit dd9855b

Browse files
committed
Fix quadratic marking, path resolution, and removal review
Batch marked-path resolution and cache display crumbs across unchanged frames. Bound removal nesting, index queue mutations, absorb descendants in one pass, and index Review status from each fresh plan. Include deterministic state/window work budgets, path and invalidation regression coverage, and measured red/green evidence. Removal authorization remains freshly revalidated before deletion.
1 parent 9b18b27 commit dd9855b

34 files changed

Lines changed: 4562 additions & 136 deletions

‎crates/disktree-app/src/marks.rs‎

Lines changed: 545 additions & 56 deletions
Large diffs are not rendered by default.

‎crates/disktree-app/src/state.rs‎

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,25 +2130,14 @@ impl Disktree {
21302130
let path = target.path.clone();
21312131
if self.marks.toggle(target) {
21322132
self.space_baseline = self.space_baseline.or(self.space);
2133-
let inside: Vec<PathBuf> = self
2134-
.marks
2135-
.items()
2136-
.iter()
2137-
.filter(|item| {
2138-
item.path != path && item.path.starts_with(&path)
2139-
})
2140-
.map(|item| item.path.clone())
2141-
.collect();
2142-
for inner in &inside {
2143-
self.marks.remove(inner);
2144-
}
2145-
if !inside.is_empty() {
2133+
let inside = self.marks.absorb(&path);
2134+
if inside > 0 {
21462135
self.notice = Some((
21472136
format!(
21482137
"{} now covers {} mark{} inside it",
21492138
display_path(&path, self.home.as_deref()),
2150-
inside.len(),
2151-
if inside.len() == 1 { "" } else { "s" }
2139+
inside,
2140+
if inside == 1 { "" } else { "s" }
21522141
),
21532142
Status::Neutral,
21542143
));
@@ -2159,12 +2148,7 @@ impl Disktree {
21592148

21602149
/// The marked directory `path` is inside, if any; never `path` itself.
21612150
pub fn marked_ancestor(&self, path: &Path) -> Option<PathBuf> {
2162-
self.marks
2163-
.items()
2164-
.iter()
2165-
.filter(|item| item.path != path && path.starts_with(&item.path))
2166-
.map(|item| item.path.clone())
2167-
.min_by_key(|ancestor| ancestor.as_os_str().len())
2151+
self.marks.ancestor(path).map(Path::to_path_buf)
21682152
}
21692153

21702154
pub fn target_at(&self, crumbs: &[usize]) -> Option<Target> {
@@ -2191,6 +2175,8 @@ impl Disktree {
21912175

21922176
/// The plan the review screen shows and the removal runs.
21932177
pub fn plan(&self) -> Plan {
2178+
#[cfg(test)]
2179+
crate::marks::work::PLANS.set(crate::marks::work::PLANS.get() + 1);
21942180
if self.remote.is_some() {
21952181
// Never judge remote paths against this machine's filesystem.
21962182
// This is an export selection, not an executable removal plan.
@@ -2221,19 +2207,17 @@ impl Disktree {
22212207
/// to draw, and the marked/hidden/selected state of every tile is decided
22222208
/// here, where the tree and the marks are both at hand.
22232209
pub fn prepare(&mut self) -> Mosaic {
2210+
#[cfg(test)]
2211+
crate::marks::work::FRAMES.set(crate::marks::work::FRAMES.get() + 1);
22242212
let metric = self.options.metric;
22252213
let view = self.view;
22262214
let hovered = self.hovered.clone();
22272215
let selected = self.selected.clone();
22282216

2229-
// Marks are paths; the mosaic thinks in crumbs. Resolve once per frame
2230-
// rather than building a path for every tile.
2231-
let mut marked: FxHashSet<Vec<usize>> = FxHashSet::default();
2232-
for item in self.marks.items() {
2233-
if let Some(crumbs) = self.crumbs_for_path(&item.path) {
2234-
marked.insert(crumbs);
2235-
}
2236-
}
2217+
let marked = self.tree.as_ref().map_or_else(
2218+
|| Arc::new(FxHashSet::default()),
2219+
|tree| self.marks.crumbs(&self.root_path, tree, metric),
2220+
);
22372221

22382222
let Some(tiles) = self.layout().map(<[Tile]>::to_vec) else {
22392223
return Mosaic {
@@ -2249,6 +2233,8 @@ impl Disktree {
22492233
let mut decorations = Vec::with_capacity(tiles.len());
22502234
let mut labels = Vec::new();
22512235
for tile in &tiles {
2236+
#[cfg(test)]
2237+
crate::marks::work::TILES.set(crate::marks::work::TILES.get() + 1);
22522238
let crumbs = tile.crumbs();
22532239
let node = match &tile.kind {
22542240
TileKind::Node { crumbs } => self.node_at(crumbs),
@@ -2356,10 +2342,11 @@ impl Disktree {
23562342
let mut crumbs = Vec::new();
23572343
for component in relative.components() {
23582344
let name = component.as_os_str().to_string_lossy();
2359-
let index = node
2360-
.children
2361-
.iter()
2362-
.position(|child| child.name.as_ref() == name)?;
2345+
let index = node.children.iter().position(|child| {
2346+
#[cfg(test)]
2347+
crate::marks::work::step();
2348+
child.name.as_ref() == name
2349+
})?;
23632350
crumbs.push(index);
23642351
node = node.child(index)?;
23652352
}
@@ -3713,6 +3700,8 @@ impl Render for Disktree {
37133700
window: &mut Window,
37143701
cx: &mut Context<'_, Self>,
37153702
) -> impl gpui_kit::IntoElement {
3703+
#[cfg(test)]
3704+
crate::marks::work::RENDERS.set(crate::marks::work::RENDERS.get() + 1);
37163705
self.rem = window.rem_size().as_f32();
37173706
self.tick_transition(window);
37183707
// The titlebar names the directory on screen, however it got there:

0 commit comments

Comments
 (0)