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()`.
This commit is contained in:
Martin von Zweigbergk 2023-11-16 07:59:46 -08:00 committed by Martin von Zweigbergk
parent c0295c5dbc
commit 9be24db051
3 changed files with 11 additions and 49 deletions

38
Cargo.lock generated
View file

@ -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"

View file

@ -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 }

View file

@ -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<Tree> 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<Self::Item> {
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));
}
}
};