cli/issue: Optimize how the issues are collected
This patch optimizes how the issues are collected. Before, the issues where pushed to a new instance of `Vec`, which was not preallocated to the size of the iterator. This could be slow when a large number of issues is returned by the iterator. With the `Iterator::collect` function, the `FromIterator` implementation of `Vec` is used, which makes use of `Iterator::size_hint` for optimizing how much space is preallocated when collecting into the `Vec`. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
b49ff9e5af
commit
f6f3be437b
|
|
@ -734,30 +734,33 @@ where
|
|||
None => None,
|
||||
};
|
||||
|
||||
let mut all = Vec::new();
|
||||
let issues = cache.list()?;
|
||||
for result in issues {
|
||||
let (id, issue) = match result {
|
||||
Ok((id, issue)) => (id, issue),
|
||||
Err(e) => {
|
||||
// Skip issues that failed to load.
|
||||
log::error!(target: "cli", "Issue load error: {e}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let mut all = cache
|
||||
.list()?
|
||||
.filter_map(|result| {
|
||||
let (id, issue) = match result {
|
||||
Ok((id, issue)) => (id, issue),
|
||||
Err(e) => {
|
||||
// Skip issues that failed to load.
|
||||
log::error!(target: "cli", "Issue load error: {e}");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(a) = assignee {
|
||||
if !issue.assignees().any(|v| v == &Did::from(a)) {
|
||||
continue;
|
||||
if let Some(a) = assignee {
|
||||
if !issue.assignees().any(|v| v == &Did::from(a)) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(s) = state {
|
||||
if s != issue.state() {
|
||||
continue;
|
||||
|
||||
if let Some(s) = state {
|
||||
if s != issue.state() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
all.push((id, issue))
|
||||
}
|
||||
|
||||
Some((id, issue))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
all.sort_by(|(id1, i1), (id2, i2)| {
|
||||
let by_timestamp = i2.timestamp().cmp(&i1.timestamp());
|
||||
|
|
|
|||
Loading…
Reference in New Issue