mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-02 09:28:40 +00:00
revset: inline ChildrenRevsetIterator by using .filter()
This commit is contained in:
parent
fae3822422
commit
5cc99b6451
1 changed files with 10 additions and 28 deletions
|
@ -32,7 +32,7 @@ use thiserror::Error;
|
||||||
|
|
||||||
use crate::backend::{BackendError, BackendResult, CommitId};
|
use crate::backend::{BackendError, BackendResult, CommitId};
|
||||||
use crate::commit::Commit;
|
use crate::commit::Commit;
|
||||||
use crate::index::{HexPrefix, IndexEntry, IndexPosition, PrefixResolution, RevWalk};
|
use crate::index::{HexPrefix, IndexEntry, PrefixResolution, RevWalk};
|
||||||
use crate::matchers::{EverythingMatcher, Matcher, PrefixMatcher};
|
use crate::matchers::{EverythingMatcher, Matcher, PrefixMatcher};
|
||||||
use crate::op_store::WorkspaceId;
|
use crate::op_store::WorkspaceId;
|
||||||
use crate::repo::RepoRef;
|
use crate::repo::RepoRef;
|
||||||
|
@ -1391,38 +1391,20 @@ struct ChildrenRevset<'revset, 'repo: 'revset> {
|
||||||
|
|
||||||
impl<'repo> Revset<'repo> for ChildrenRevset<'_, 'repo> {
|
impl<'repo> Revset<'repo> for ChildrenRevset<'_, 'repo> {
|
||||||
fn iter<'revset>(&'revset self) -> RevsetIterator<'revset, 'repo> {
|
fn iter<'revset>(&'revset self) -> RevsetIterator<'revset, 'repo> {
|
||||||
let roots = self
|
let roots: HashSet<_> = self
|
||||||
.root_set
|
.root_set
|
||||||
.iter()
|
.iter()
|
||||||
.map(|parent| parent.position())
|
.map(|parent| parent.position())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
RevsetIterator::new(Box::new(ChildrenRevsetIterator {
|
RevsetIterator::new(Box::new(self.candidate_set.iter().filter(
|
||||||
candidate_iter: self.candidate_set.iter(),
|
move |candidate| {
|
||||||
roots,
|
candidate
|
||||||
}))
|
.parent_positions()
|
||||||
}
|
.iter()
|
||||||
}
|
.any(|parent_pos| roots.contains(parent_pos))
|
||||||
|
},
|
||||||
struct ChildrenRevsetIterator<'revset, 'repo> {
|
)))
|
||||||
candidate_iter: RevsetIterator<'revset, 'repo>,
|
|
||||||
roots: HashSet<IndexPosition>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'repo> Iterator for ChildrenRevsetIterator<'_, 'repo> {
|
|
||||||
type Item = IndexEntry<'repo>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
loop {
|
|
||||||
let candidate = self.candidate_iter.next()?;
|
|
||||||
if candidate
|
|
||||||
.parent_positions()
|
|
||||||
.iter()
|
|
||||||
.any(|parent_pos| self.roots.contains(parent_pos))
|
|
||||||
{
|
|
||||||
return Some(candidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue