MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / merge_hunks

Function merge_hunks

atomic-core/src/diff/inline.rs:756–774  ·  view source on GitHub ↗

Merge adjacent hunks of the same kind.

(hunks: Vec<ChangeHunk>)

Source from the content-addressed store, hash-verified

754
755/// Merge adjacent hunks of the same kind.
756fn merge_hunks(hunks: Vec<ChangeHunk>) -> Vec<ChangeHunk> {
757 if hunks.is_empty() {
758 return hunks;
759 }
760
761 let mut merged: Vec<ChangeHunk> = Vec::with_capacity(hunks.len());
762
763 for hunk in hunks {
764 if let Some(last) = merged.last_mut() {
765 if let Some(combined) = last.try_merge(&hunk) {
766 *last = combined;
767 continue;
768 }
769 }
770 merged.push(hunk);
771 }
772
773 merged
774}
775
776/// Fill gaps between hunks with unchanged hunks.
777fn fill_gaps(mut hunks: Vec<ChangeHunk>, total_len: usize) -> Vec<ChangeHunk> {

Callers 2

test_merge_hunksFunction · 0.85

Calls 4

is_emptyMethod · 0.45
lenMethod · 0.45
try_mergeMethod · 0.45
pushMethod · 0.45

Tested by 1

test_merge_hunksFunction · 0.68