mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 16:53:25 +00:00
merge: load legacy Merge values without allocating intermediate buffers
This commit is contained in:
parent
09987c1d27
commit
803b41c426
1 changed files with 7 additions and 9 deletions
|
@ -154,16 +154,14 @@ impl<T> Merge<T> {
|
|||
removes: impl IntoIterator<Item = T>,
|
||||
adds: impl IntoIterator<Item = T>,
|
||||
) -> Merge<Option<T>> {
|
||||
// TODO: no need to build intermediate removes/adds vecs
|
||||
let mut removes = removes.into_iter().map(Some).collect_vec();
|
||||
let mut adds = adds.into_iter().map(Some).collect_vec();
|
||||
while removes.len() + 1 < adds.len() {
|
||||
removes.push(None);
|
||||
let removes = removes.into_iter();
|
||||
let mut adds = adds.into_iter().fuse();
|
||||
let mut values = smallvec_inline![adds.next()];
|
||||
for diff in removes.zip_longest(adds) {
|
||||
let (remove, add) = diff.map_any(Some, Some).or_default();
|
||||
values.extend([remove, add]);
|
||||
}
|
||||
while adds.len() < removes.len() + 1 {
|
||||
adds.push(None);
|
||||
}
|
||||
Merge::new(removes, adds)
|
||||
Merge { values }
|
||||
}
|
||||
|
||||
/// The removed values, also called negative terms.
|
||||
|
|
Loading…
Reference in a new issue