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

Function merge_equal_ops

atomic-core/src/diff/patience.rs:343–373  ·  view source on GitHub ↗

Merge consecutive Equal operations in the result.

(result: &mut DiffResult)

Source from the content-addressed store, hash-verified

341
342/// Merge consecutive Equal operations in the result.
343fn merge_equal_ops(result: &mut DiffResult) {
344 // Take ownership of the ops by replacing with empty DiffResult
345 let old_result = std::mem::take(result);
346 let ops = old_result.into_ops();
347 let mut merged = Vec::with_capacity(ops.len());
348
349 for op in ops {
350 if let DiffOp::Equal {
351 old_pos,
352 new_pos,
353 len,
354 } = op
355 {
356 // Check if we can merge with the previous operation
357 if let Some(DiffOp::Equal {
358 old_pos: prev_old,
359 new_pos: prev_new,
360 len: prev_len,
361 }) = merged.last_mut()
362 {
363 if *prev_old + *prev_len == old_pos && *prev_new + *prev_len == new_pos {
364 *prev_len += len;
365 continue;
366 }
367 }
368 }
369 merged.push(op);
370 }
371
372 *result = DiffResult::with_ops(merged);
373}
374
375#[cfg(test)]
376mod tests {

Callers 2

diff_with_anchorsFunction · 0.85
test_merge_equal_opsFunction · 0.85

Calls 3

into_opsMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by 1

test_merge_equal_opsFunction · 0.68