History

sum_tree: Store context on cursor (#34904)

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

Piotr Osiewicz committed 1 year ago

Commit 64d0fec1 parent fa3e1cc23 files · +749 −876Browse files

Showing the changes to crates/buffer_diff/src/buffer_diff.rs (1 of 23 files). Show all

Unified · Split

crates/buffer_diff/src/buffer_diff.rs+20−22
@@ -343,8 +343,7 @@ impl BufferDiffInner { · 342 unmodified lines
343343 ..
344344 } in hunks.iter().cloned()
345345 {
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);
348347 pending_hunks.append(preceding_pending_hunks, buffer);
349348
350349 // Skip all overlapping or adjacent old pending hunks
@@ -355,7 +354,7 @@ impl BufferDiffInner { · 4 unmodified lines
355354 .cmp(&buffer_range.end, buffer)
356355 .is_le()
357356 }) {
358− old_pending_hunks.next(buffer);
357+ old_pending_hunks.next();
359358 }
360359
361360 if (stage && secondary_status == DiffHunkSecondaryStatus::NoSecondaryHunk)
@@ -379,10 +378,10 @@ impl BufferDiffInner { · 17 unmodified lines
379378 );
380379 }
381380 // append the remainder
382− pending_hunks.append(old_pending_hunks.suffix(buffer), buffer);
381+ pending_hunks.append(old_pending_hunks.suffix(), buffer);
383382
384383 let mut unstaged_hunk_cursor = unstaged_diff.hunks.cursor::<DiffHunkSummary>(buffer);
385− unstaged_hunk_cursor.next(buffer);
384+ unstaged_hunk_cursor.next();
386385
387386 // then, iterate over all pending hunks (both new ones and the existing ones) and compute the edits
388387 let mut prev_unstaged_hunk_buffer_end = 0;
@@ -397,8 +396,7 @@ impl BufferDiffInner { · 8 unmodified lines
397396 }) = pending_hunks_iter.next()
398397 {
399398 // 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);
402400
403401 if let Some(unstaged_hunk) = skipped_unstaged.last() {
404402 prev_unstaged_hunk_base_text_end = unstaged_hunk.diff_base_byte_range.end;
@@ -425,7 +423,7 @@ impl BufferDiffInner { · 20 unmodified lines
425423 buffer_offset_range.end =
426424 buffer_offset_range.end.max(unstaged_hunk_offset_range.end);
427425
428− unstaged_hunk_cursor.next(buffer);
426+ unstaged_hunk_cursor.next();
429427 continue;
430428 }
431429 }
@@ -514,7 +512,7 @@ impl BufferDiffInner { · 82 unmodified lines
514512 });
515513
516514 let anchor_iter = iter::from_fn(move || {
517− cursor.next(buffer);
515+ cursor.next();
518516 cursor.item()
519517 })
520518 .flat_map(move |hunk| {
@@ -531,12 +529,12 @@ impl BufferDiffInner { · 10 unmodified lines
531529 });
532530
533531 let mut pending_hunks_cursor = self.pending_hunks.cursor::<DiffHunkSummary>(buffer);
534− pending_hunks_cursor.next(buffer);
532+ pending_hunks_cursor.next();
535533
536534 let mut secondary_cursor = None;
537535 if let Some(secondary) = secondary.as_ref() {
538536 let mut cursor = secondary.hunks.cursor::<DiffHunkSummary>(buffer);
539− cursor.next(buffer);
537+ cursor.next();
540538 secondary_cursor = Some(cursor);
541539 }
542540
@@ -564,7 +562,7 @@ impl BufferDiffInner { · 21 unmodified lines
564562 .cmp(&pending_hunks_cursor.start().buffer_range.start, buffer)
565563 .is_gt()
566564 {
567− pending_hunks_cursor.seek_forward(&start_anchor, Bias::Left, buffer);
565+ pending_hunks_cursor.seek_forward(&start_anchor, Bias::Left);
568566 }
569567
570568 if let Some(pending_hunk) = pending_hunks_cursor.item() {
@@ -590,7 +588,7 @@ impl BufferDiffInner { · 19 unmodified lines
590588 .cmp(&secondary_cursor.start().buffer_range.start, buffer)
591589 .is_gt()
592590 {
593− secondary_cursor.seek_forward(&start_anchor, Bias::Left, buffer);
591+ secondary_cursor.seek_forward(&start_anchor, Bias::Left);
594592 }
595593
596594 if let Some(secondary_hunk) = secondary_cursor.item() {
@@ -635,7 +633,7 @@ impl BufferDiffInner { · 38 unmodified lines
635633 });
636634
637635 iter::from_fn(move || {
638− cursor.prev(buffer);
636+ cursor.prev();
639637
640638 let hunk = cursor.item()?;
641639 let range = hunk.buffer_range.to_point(buffer);
@@ -653,8 +651,8 @@ impl BufferDiffInner { · 11 unmodified lines
653651 fn compare(&self, old: &Self, new_snapshot: &text::BufferSnapshot) -> Option<Range<Anchor>> {
654652 let mut new_cursor = self.hunks.cursor::<()>(new_snapshot);
655653 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();
658656 let mut start = None;
659657 let mut end = None;
660658
@@ -669,7 +667,7 @@ impl BufferDiffInner { · 8 unmodified lines
669667 Ordering::Less => {
670668 start.get_or_insert(new_hunk.buffer_range.start);
671669 end.replace(new_hunk.buffer_range.end);
672− new_cursor.next(new_snapshot);
670+ new_cursor.next();
673671 }
674672 Ordering::Equal => {
675673 if new_hunk != old_hunk {
@@ -686,25 +684,25 @@ impl BufferDiffInner { · 10 unmodified lines
686684 }
687685 }
688686
689− new_cursor.next(new_snapshot);
690− old_cursor.next(new_snapshot);
687+ new_cursor.next();
688+ old_cursor.next();
691689 }
692690 Ordering::Greater => {
693691 start.get_or_insert(old_hunk.buffer_range.start);
694692 end.replace(old_hunk.buffer_range.end);
695− old_cursor.next(new_snapshot);
693+ old_cursor.next();
696694 }
697695 }
698696 }
699697 (Some(new_hunk), None) => {
700698 start.get_or_insert(new_hunk.buffer_range.start);
701699 end.replace(new_hunk.buffer_range.end);
702− new_cursor.next(new_snapshot);
700+ new_cursor.next();
703701 }
704702 (None, Some(old_hunk)) => {
705703 start.get_or_insert(old_hunk.buffer_range.start);
706704 end.replace(old_hunk.buffer_range.end);
707− old_cursor.next(new_snapshot);
705+ old_cursor.next();
708706 }
709707 (None, None) => break,
710708 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t