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

Method adjust_offsets

atomic-core/src/diff/ops.rs:505–534  ·  view source on GitHub ↗

Adjust all operation offsets by adding to the positions. This is used after stripping common prefixes to restore correct positions.

(&mut self, offset: usize)

Source from the content-addressed store, hash-verified

503 ///
504 /// This is used after stripping common prefixes to restore correct positions.
505 pub(crate) fn adjust_offsets(&mut self, offset: usize) {
506 for op in &mut self.ops {
507 match op {
508 DiffOp::Equal {
509 old_pos, new_pos, ..
510 } => {
511 *old_pos += offset;
512 *new_pos += offset;
513 }
514 DiffOp::Insert {
515 old_pos, new_pos, ..
516 } => {
517 *old_pos += offset;
518 *new_pos += offset;
519 }
520 DiffOp::Delete {
521 old_pos, new_pos, ..
522 } => {
523 *old_pos += offset;
524 *new_pos += offset;
525 }
526 DiffOp::Replace {
527 old_pos, new_pos, ..
528 } => {
529 *old_pos += offset;
530 *new_pos += offset;
531 }
532 }
533 }
534 }
535
536 /// Prepend an Equal operation at the start.
537 pub(crate) fn prepend_equal(&mut self, old_pos: usize, len: usize) {

Callers 3

test_adjust_offsetsFunction · 0.80
patience_diff_recursiveFunction · 0.80
diff_with_optionsFunction · 0.80

Calls

no outgoing calls

Tested by 1

test_adjust_offsetsFunction · 0.64