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