This gets rid of the need to pass context to all cursor functions. In practice context is always immutable when interacting with cursors. A nicety of this is in the follow-up PR we will be able to implement Iterator for all Cursors/filter cursors (hell, we may be able to get rid of filter cursor altogether, as it is just a custom `filter` impl on iterator trait). Release Notes: - N/A
Showing the changes to crates/buffer_diff/src/buffer_diff.rs (1 of 23 files). Show all
Unified · Split
| @@ -343,8 +343,7 @@ impl BufferDiffInner { · 342 unmodified lines | ||
| 343 | 343 | .. |
| 344 | 344 | } in hunks.iter().cloned() |
| 345 | 345 | { |
| 346 | − let preceding_pending_hunks = | |
| 347 | − old_pending_hunks.slice(&buffer_range.start, Bias::Left, buffer); | |
| 346 | + let preceding_pending_hunks = old_pending_hunks.slice(&buffer_range.start, Bias::Left); | |
| 348 | 347 | pending_hunks.append(preceding_pending_hunks, buffer); |
| 349 | 348 | |
| 350 | 349 | // Skip all overlapping or adjacent old pending hunks |
| @@ -355,7 +354,7 @@ impl BufferDiffInner { · 4 unmodified lines | ||
| 355 | 354 | .cmp(&buffer_range.end, buffer) |
| 356 | 355 | .is_le() |
| 357 | 356 | }) { |
| 358 | − old_pending_hunks.next(buffer); | |
| 357 | + old_pending_hunks.next(); | |
| 359 | 358 | } |
| 360 | 359 | |
| 361 | 360 | if (stage && secondary_status == DiffHunkSecondaryStatus::NoSecondaryHunk) |
| @@ -379,10 +378,10 @@ impl BufferDiffInner { · 17 unmodified lines | ||
| 379 | 378 | ); |
| 380 | 379 | } |
| 381 | 380 | // append the remainder |
| 382 | − pending_hunks.append(old_pending_hunks.suffix(buffer), buffer); | |
| 381 | + pending_hunks.append(old_pending_hunks.suffix(), buffer); | |
| 383 | 382 | |
| 384 | 383 | let mut unstaged_hunk_cursor = unstaged_diff.hunks.cursor::<DiffHunkSummary>(buffer); |
| 385 | − unstaged_hunk_cursor.next(buffer); | |
| 384 | + unstaged_hunk_cursor.next(); | |
| 386 | 385 | |
| 387 | 386 | // then, iterate over all pending hunks (both new ones and the existing ones) and compute the edits |
| 388 | 387 | let mut prev_unstaged_hunk_buffer_end = 0; |
| @@ -397,8 +396,7 @@ impl BufferDiffInner { · 8 unmodified lines | ||
| 397 | 396 | }) = pending_hunks_iter.next() |
| 398 | 397 | { |
| 399 | 398 | // Advance unstaged_hunk_cursor to skip unstaged hunks before current hunk |
| 400 | − let skipped_unstaged = | |
| 401 | − unstaged_hunk_cursor.slice(&buffer_range.start, Bias::Left, buffer); | |
| 399 | + let skipped_unstaged = unstaged_hunk_cursor.slice(&buffer_range.start, Bias::Left); | |
| 402 | 400 | |
| 403 | 401 | if let Some(unstaged_hunk) = skipped_unstaged.last() { |
| 404 | 402 | prev_unstaged_hunk_base_text_end = unstaged_hunk.diff_base_byte_range.end; |
| @@ -425,7 +423,7 @@ impl BufferDiffInner { · 20 unmodified lines | ||
| 425 | 423 | buffer_offset_range.end = |
| 426 | 424 | buffer_offset_range.end.max(unstaged_hunk_offset_range.end); |
| 427 | 425 | |
| 428 | − unstaged_hunk_cursor.next(buffer); | |
| 426 | + unstaged_hunk_cursor.next(); | |
| 429 | 427 | continue; |
| 430 | 428 | } |
| 431 | 429 | } |
| @@ -514,7 +512,7 @@ impl BufferDiffInner { · 82 unmodified lines | ||
| 514 | 512 | }); |
| 515 | 513 | |
| 516 | 514 | let anchor_iter = iter::from_fn(move || { |
| 517 | − cursor.next(buffer); | |
| 515 | + cursor.next(); | |
| 518 | 516 | cursor.item() |
| 519 | 517 | }) |
| 520 | 518 | .flat_map(move |hunk| { |
| @@ -531,12 +529,12 @@ impl BufferDiffInner { · 10 unmodified lines | ||
| 531 | 529 | }); |
| 532 | 530 | |
| 533 | 531 | let mut pending_hunks_cursor = self.pending_hunks.cursor::<DiffHunkSummary>(buffer); |
| 534 | − pending_hunks_cursor.next(buffer); | |
| 532 | + pending_hunks_cursor.next(); | |
| 535 | 533 | |
| 536 | 534 | let mut secondary_cursor = None; |
| 537 | 535 | if let Some(secondary) = secondary.as_ref() { |
| 538 | 536 | let mut cursor = secondary.hunks.cursor::<DiffHunkSummary>(buffer); |
| 539 | − cursor.next(buffer); | |
| 537 | + cursor.next(); | |
| 540 | 538 | secondary_cursor = Some(cursor); |
| 541 | 539 | } |
| 542 | 540 | |
| @@ -564,7 +562,7 @@ impl BufferDiffInner { · 21 unmodified lines | ||
| 564 | 562 | .cmp(&pending_hunks_cursor.start().buffer_range.start, buffer) |
| 565 | 563 | .is_gt() |
| 566 | 564 | { |
| 567 | − pending_hunks_cursor.seek_forward(&start_anchor, Bias::Left, buffer); | |
| 565 | + pending_hunks_cursor.seek_forward(&start_anchor, Bias::Left); | |
| 568 | 566 | } |
| 569 | 567 | |
| 570 | 568 | if let Some(pending_hunk) = pending_hunks_cursor.item() { |
| @@ -590,7 +588,7 @@ impl BufferDiffInner { · 19 unmodified lines | ||
| 590 | 588 | .cmp(&secondary_cursor.start().buffer_range.start, buffer) |
| 591 | 589 | .is_gt() |
| 592 | 590 | { |
| 593 | − secondary_cursor.seek_forward(&start_anchor, Bias::Left, buffer); | |
| 591 | + secondary_cursor.seek_forward(&start_anchor, Bias::Left); | |
| 594 | 592 | } |
| 595 | 593 | |
| 596 | 594 | if let Some(secondary_hunk) = secondary_cursor.item() { |
| @@ -635,7 +633,7 @@ impl BufferDiffInner { · 38 unmodified lines | ||
| 635 | 633 | }); |
| 636 | 634 | |
| 637 | 635 | iter::from_fn(move || { |
| 638 | − cursor.prev(buffer); | |
| 636 | + cursor.prev(); | |
| 639 | 637 | |
| 640 | 638 | let hunk = cursor.item()?; |
| 641 | 639 | let range = hunk.buffer_range.to_point(buffer); |
| @@ -653,8 +651,8 @@ impl BufferDiffInner { · 11 unmodified lines | ||
| 653 | 651 | fn compare(&self, old: &Self, new_snapshot: &text::BufferSnapshot) -> Option<Range<Anchor>> { |
| 654 | 652 | let mut new_cursor = self.hunks.cursor::<()>(new_snapshot); |
| 655 | 653 | let mut old_cursor = old.hunks.cursor::<()>(new_snapshot); |
| 656 | − old_cursor.next(new_snapshot); | |
| 657 | − new_cursor.next(new_snapshot); | |
| 654 | + old_cursor.next(); | |
| 655 | + new_cursor.next(); | |
| 658 | 656 | let mut start = None; |
| 659 | 657 | let mut end = None; |
| 660 | 658 | |
| @@ -669,7 +667,7 @@ impl BufferDiffInner { · 8 unmodified lines | ||
| 669 | 667 | Ordering::Less => { |
| 670 | 668 | start.get_or_insert(new_hunk.buffer_range.start); |
| 671 | 669 | end.replace(new_hunk.buffer_range.end); |
| 672 | − new_cursor.next(new_snapshot); | |
| 670 | + new_cursor.next(); | |
| 673 | 671 | } |
| 674 | 672 | Ordering::Equal => { |
| 675 | 673 | if new_hunk != old_hunk { |
| @@ -686,25 +684,25 @@ impl BufferDiffInner { · 10 unmodified lines | ||
| 686 | 684 | } |
| 687 | 685 | } |
| 688 | 686 | |
| 689 | − new_cursor.next(new_snapshot); | |
| 690 | − old_cursor.next(new_snapshot); | |
| 687 | + new_cursor.next(); | |
| 688 | + old_cursor.next(); | |
| 691 | 689 | } |
| 692 | 690 | Ordering::Greater => { |
| 693 | 691 | start.get_or_insert(old_hunk.buffer_range.start); |
| 694 | 692 | end.replace(old_hunk.buffer_range.end); |
| 695 | − old_cursor.next(new_snapshot); | |
| 693 | + old_cursor.next(); | |
| 696 | 694 | } |
| 697 | 695 | } |
| 698 | 696 | } |
| 699 | 697 | (Some(new_hunk), None) => { |
| 700 | 698 | start.get_or_insert(new_hunk.buffer_range.start); |
| 701 | 699 | end.replace(new_hunk.buffer_range.end); |
| 702 | − new_cursor.next(new_snapshot); | |
| 700 | + new_cursor.next(); | |
| 703 | 701 | } |
| 704 | 702 | (None, Some(old_hunk)) => { |
| 705 | 703 | start.get_or_insert(old_hunk.buffer_range.start); |
| 706 | 704 | end.replace(old_hunk.buffer_range.end); |
| 707 | − old_cursor.next(new_snapshot); | |
| 705 | + old_cursor.next(); | |
| 708 | 706 | } |
| 709 | 707 | (None, None) => break, |
| 710 | 708 | } |