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

Function fill_gaps

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

Fill gaps between hunks with unchanged hunks.

(mut hunks: Vec<ChangeHunk>, total_len: usize)

Source from the content-addressed store, hash-verified

775
776/// Fill gaps between hunks with unchanged hunks.
777fn fill_gaps(mut hunks: Vec<ChangeHunk>, total_len: usize) -> Vec<ChangeHunk> {
778 if hunks.is_empty() {
779 if total_len > 0 {
780 return vec![ChangeHunk::unchanged(0, total_len)];
781 }
782 return hunks;
783 }
784
785 // Sort by start position
786 hunks.sort_by_key(|s| s.start);
787
788 let mut filled: Vec<ChangeHunk> = Vec::with_capacity(hunks.len() * 2);
789 let mut current_pos = 0;
790
791 for hunk in hunks {
792 // Fill gap before this hunk
793 if hunk.start > current_pos {
794 filled.push(ChangeHunk::unchanged(current_pos, hunk.start));
795 }
796
797 filled.push(hunk.clone());
798 current_pos = hunk.end;
799 }
800
801 // Fill gap at the end
802 if current_pos < total_len {
803 filled.push(ChangeHunk::unchanged(current_pos, total_len));
804 }
805
806 filled
807}
808
809/// Configuration for inline diff display.
810///

Callers 3

test_fill_gapsFunction · 0.85
test_fill_gaps_emptyFunction · 0.85

Calls 4

is_emptyMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by 2

test_fill_gapsFunction · 0.68
test_fill_gaps_emptyFunction · 0.68