From 9be24db05187dfcfbca459a5387ed13fef29e8a2 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 16 Nov 2023 07:59:46 -0800 Subject: [PATCH] tree: make TreeEntriesDirItem not self-referential This removes the last use of `ouroboros`. Since `TreeEntriesDirItem` is only used in "legacy trees" (before tree-level conflicts), I didn't bother to check the performance impact. I also didn't bother to check the matcher before adding the entries to the list, instead leaving that where it is in `Iterator::next()`. --- Cargo.lock | 38 -------------------------------------- lib/Cargo.toml | 1 - lib/src/tree.rs | 21 +++++++++++---------- 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14d0eb339..36823dd54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,12 +26,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aliasable" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" - [[package]] name = "android-tzdata" version = "0.1.1" @@ -1679,7 +1673,6 @@ dependencies = [ "maplit", "num_cpus", "once_cell", - "ouroboros", "pest", "pest_derive", "pollster", @@ -1989,31 +1982,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "ouroboros" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c86de06555b970aec45229b27291b53154f21a5743a163419f4e4c0b065dcde" -dependencies = [ - "aliasable", - "ouroboros_macro", - "static_assertions", -] - -[[package]] -name = "ouroboros_macro" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cad0c4b129e9696e37cb712b243777b90ef489a0bfaa0ac34e7d9b860e4f134" -dependencies = [ - "heck", - "itertools 0.11.0", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.37", -] - [[package]] name = "overload" version = "0.1.1" @@ -2701,12 +2669,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 2bd52db76..a9f719b74 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -36,7 +36,6 @@ hex = { workspace = true } itertools = { workspace = true } maplit = { workspace = true } once_cell = { workspace = true } -ouroboros = { workspace = true } pest = { workspace = true } pest_derive = { workspace = true } pollster = { workspace = true } diff --git a/lib/src/tree.rs b/lib/src/tree.rs index 804080c0f..bc6443329 100644 --- a/lib/src/tree.rs +++ b/lib/src/tree.rs @@ -196,17 +196,19 @@ pub struct TreeEntriesIterator<'matcher> { matcher: &'matcher dyn Matcher, } -#[ouroboros::self_referencing] struct TreeEntriesDirItem { tree: Tree, - #[borrows(tree)] - #[not_covariant] - entry_iterator: TreeEntriesNonRecursiveIterator<'this>, + entries: Vec<(RepoPath, TreeValue)>, } impl From for TreeEntriesDirItem { fn from(tree: Tree) -> Self { - Self::new(tree, |tree| tree.entries_non_recursive()) + let mut entries = tree + .entries_non_recursive() + .map(|entry| (tree.dir().join(entry.name()), entry.value().clone())) + .collect_vec(); + entries.reverse(); + Self { tree, entries } } } @@ -225,20 +227,19 @@ impl Iterator for TreeEntriesIterator<'_> { fn next(&mut self) -> Option { while let Some(top) = self.stack.last_mut() { - if let (tree, Some(entry)) = top.with_mut(|x| (x.tree, x.entry_iterator.next())) { - let path = tree.dir().join(entry.name()); - match entry.value() { + if let Some((path, value)) = top.entries.pop() { + match value { TreeValue::Tree(id) => { // TODO: Handle the other cases (specific files and trees) if self.matcher.visit(&path).is_nothing() { continue; } - let subtree = tree.known_sub_tree(&path, id); + let subtree = top.tree.known_sub_tree(&path, &id); self.stack.push(TreeEntriesDirItem::from(subtree)); } value => { if self.matcher.matches(&path) { - return Some((path, value.clone())); + return Some((path, value)); } } };