History

sum_tree: Replace rayon with futures (#41586)

Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored by: Kate <kate@zed.dev>

Lukas Wirth committed 1 year ago

Commit f2ce06c1 parent 7c29c6d67 files · +1271 −640Browse files

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

Unified · Split

crates/buffer_diff/src/buffer_diff.rs+47−11
@@ -1,6 +1,9 @@
1use futures::channel::oneshot;1use futures::channel::oneshot;
2use git2::{DiffLineType as GitDiffLineType, DiffOptions as GitOptions, Patch as GitPatch};2use git2::{DiffLineType as GitDiffLineType, DiffOptions as GitOptions, Patch as GitPatch};
3use gpui::{App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, Task, TaskLabel};3use gpui::{
4 App, AppContext as _, AsyncApp, BackgroundExecutor, Context, Entity, EventEmitter, Task,
5 TaskLabel,
6};
4use language::{Language, LanguageRegistry};7use language::{Language, LanguageRegistry};
5use rope::Rope;8use rope::Rope;
6use std::{9use std::{
@@ -191,7 +194,7 @@ impl BufferDiffSnapshot { · 184 unmodified lines
191 let base_text_exists;194 let base_text_exists;
192 let base_text_snapshot;195 let base_text_snapshot;
193 if let Some(text) = &base_text {196 if let Some(text) = &base_text {
194 let base_text_rope = Rope::from(text.as_str());197 let base_text_rope = Rope::from_str(text.as_str(), cx.background_executor());
195 base_text_pair = Some((text.clone(), base_text_rope.clone()));198 base_text_pair = Some((text.clone(), base_text_rope.clone()));
196 let snapshot =199 let snapshot =
197 language::Buffer::build_snapshot(base_text_rope, language, language_registry, cx);200 language::Buffer::build_snapshot(base_text_rope, language, language_registry, cx);
@@ -311,6 +314,7 @@ impl BufferDiffInner { · 113 unmodified lines
311 hunks: &[DiffHunk],314 hunks: &[DiffHunk],
312 buffer: &text::BufferSnapshot,315 buffer: &text::BufferSnapshot,
313 file_exists: bool,316 file_exists: bool,
317 cx: &BackgroundExecutor,
314 ) -> Option<Rope> {318 ) -> Option<Rope> {
315 let head_text = self319 let head_text = self
316 .base_text_exists320 .base_text_exists
@@ -505,7 +509,7 @@ impl BufferDiffInner { · 188 unmodified lines
505 for (old_range, replacement_text) in edits {509 for (old_range, replacement_text) in edits {
506 new_index_text.append(index_cursor.slice(old_range.start));510 new_index_text.append(index_cursor.slice(old_range.start));
507 index_cursor.seek_forward(old_range.end);511 index_cursor.seek_forward(old_range.end);
508 new_index_text.push(&replacement_text);512 new_index_text.push(&replacement_text, cx);
509 }513 }
510 new_index_text.append(index_cursor.suffix());514 new_index_text.append(index_cursor.suffix());
511 Some(new_index_text)515 Some(new_index_text)
@@ -962,6 +966,7 @@ impl BufferDiff { · 450 unmodified lines
962 hunks,966 hunks,
963 buffer,967 buffer,
964 file_exists,968 file_exists,
969 cx.background_executor(),
965 );970 );
966 971
967 cx.emit(BufferDiffEvent::HunksStagedOrUnstaged(972 cx.emit(BufferDiffEvent::HunksStagedOrUnstaged(
@@ -1385,7 +1390,12 @@ mod tests { · 417 unmodified lines
1385 "1390 "
1386 .unindent();1391 .unindent();
1387 1392
1388 let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text);1393 let mut buffer = Buffer::new(
1394 ReplicaId::LOCAL,
1395 BufferId::new(1).unwrap(),
1396 buffer_text,
1397 cx.background_executor(),
1398 );
1389 let mut diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx);1399 let mut diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx);
1390 assert_hunks(1400 assert_hunks(
1391 diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer),1401 diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer),
@@ -1394,7 +1404,7 @@ mod tests { · 2 unmodified lines
1394 &[(1..2, "two\n", "HELLO\n", DiffHunkStatus::modified_none())],1404 &[(1..2, "two\n", "HELLO\n", DiffHunkStatus::modified_none())],
1395 );1405 );
1396 1406
1397 buffer.edit([(0..0, "point five\n")]);1407 buffer.edit([(0..0, "point five\n")], cx.background_executor());
1398 diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx);1408 diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx);
1399 assert_hunks(1409 assert_hunks(
1400 diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer),1410 diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer),
@@ -1459,7 +1469,12 @@ mod tests { · 58 unmodified lines
1459 "1469 "
1460 .unindent();1470 .unindent();
1461 1471
1462 let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text);1472 let buffer = Buffer::new(
1473 ReplicaId::LOCAL,
1474 BufferId::new(1).unwrap(),
1475 buffer_text,
1476 cx.background_executor(),
1477 );
1463 let unstaged_diff = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx);1478 let unstaged_diff = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx);
1464 let mut uncommitted_diff =1479 let mut uncommitted_diff =
1465 BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx);1480 BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx);
@@ -1528,7 +1543,12 @@ mod tests { · 62 unmodified lines
1528 "1543 "
1529 .unindent();1544 .unindent();
1530 1545
1531 let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text);1546 let buffer = Buffer::new(
1547 ReplicaId::LOCAL,
1548 BufferId::new(1).unwrap(),
1549 buffer_text,
1550 cx.background_executor(),
1551 );
1532 let diff = cx1552 let diff = cx
1533 .update(|cx| {1553 .update(|cx| {
1534 BufferDiffSnapshot::new_with_base_text(1554 BufferDiffSnapshot::new_with_base_text(
@@ -1791,7 +1811,12 @@ mod tests { · 256 unmodified lines
1791 1811
1792 for example in table {1812 for example in table {
1793 let (buffer_text, ranges) = marked_text_ranges(&example.buffer_marked_text, false);1813 let (buffer_text, ranges) = marked_text_ranges(&example.buffer_marked_text, false);
1794 let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text);1814 let buffer = Buffer::new(
1815 ReplicaId::LOCAL,
1816 BufferId::new(1).unwrap(),
1817 buffer_text,
1818 cx.background_executor(),
1819 );
1795 let hunk_range =1820 let hunk_range =
1796 buffer.anchor_before(ranges[0].start)..buffer.anchor_before(ranges[0].end);1821 buffer.anchor_before(ranges[0].start)..buffer.anchor_before(ranges[0].end);
1797 1822
@@ -1868,6 +1893,7 @@ mod tests { · 70 unmodified lines
1868 ReplicaId::LOCAL,1893 ReplicaId::LOCAL,
1869 BufferId::new(1).unwrap(),1894 BufferId::new(1).unwrap(),
1870 buffer_text.clone(),1895 buffer_text.clone(),
1896 cx.background_executor(),
1871 );1897 );
1872 let unstaged = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx);1898 let unstaged = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx);
1873 let uncommitted = BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx);1899 let uncommitted = BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx);
@@ -1941,7 +1967,12 @@ mod tests { · 67 unmodified lines
1941 "1967 "
1942 .unindent();1968 .unindent();
1943 1969
1944 let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text_1);1970 let mut buffer = Buffer::new(
1971 ReplicaId::LOCAL,
1972 BufferId::new(1).unwrap(),
1973 buffer_text_1,
1974 cx.background_executor(),
1975 );
1945 1976
1946 let empty_diff = cx.update(|cx| BufferDiffSnapshot::empty(&buffer, cx));1977 let empty_diff = cx.update(|cx| BufferDiffSnapshot::empty(&buffer, cx));
1947 let diff_1 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);1978 let diff_1 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
@@ -1961,6 +1992,7 @@ mod tests { · 13 unmodified lines
1961 NINE1992 NINE
1962 "1993 "
1963 .unindent(),1994 .unindent(),
1995 cx.background_executor(),
1964 );1996 );
1965 let diff_2 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);1997 let diff_2 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
1966 assert_eq!(None, diff_2.inner.compare(&diff_1.inner, &buffer));1998 assert_eq!(None, diff_2.inner.compare(&diff_1.inner, &buffer));
@@ -1978,6 +2010,7 @@ mod tests { · 11 unmodified lines
1978 NINE2010 NINE
1979 "2011 "
1980 .unindent(),2012 .unindent(),
2013 cx.background_executor(),
1981 );2014 );
1982 let diff_3 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);2015 let diff_3 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
1983 let range = diff_3.inner.compare(&diff_2.inner, &buffer).unwrap();2016 let range = diff_3.inner.compare(&diff_2.inner, &buffer).unwrap();
@@ -1995,6 +2028,7 @@ mod tests { · 11 unmodified lines
1995 NINE2028 NINE
1996 "2029 "
1997 .unindent(),2030 .unindent(),
2031 cx.background_executor(),
1998 );2032 );
1999 let diff_4 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);2033 let diff_4 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
2000 let range = diff_4.inner.compare(&diff_3.inner, &buffer).unwrap();2034 let range = diff_4.inner.compare(&diff_3.inner, &buffer).unwrap();
@@ -2013,6 +2047,7 @@ mod tests { · 12 unmodified lines
2013 NINE2047 NINE
2014 "2048 "
2015 .unindent(),2049 .unindent(),
2050 cx.background_executor(),
2016 );2051 );
2017 let diff_5 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text.clone(), cx);2052 let diff_5 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text.clone(), cx);
2018 let range = diff_5.inner.compare(&diff_4.inner, &buffer).unwrap();2053 let range = diff_5.inner.compare(&diff_4.inner, &buffer).unwrap();
@@ -2031,6 +2066,7 @@ mod tests { · 12 unmodified lines
2031 «nine»2066 «nine»
2032 "2067 "
2033 .unindent(),2068 .unindent(),
2069 cx.background_executor(),
2034 );2070 );
2035 let diff_6 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text, cx);2071 let diff_6 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text, cx);
2036 let range = diff_6.inner.compare(&diff_5.inner, &buffer).unwrap();2072 let range = diff_6.inner.compare(&diff_5.inner, &buffer).unwrap();
@@ -2140,14 +2176,14 @@ mod tests { · 103 unmodified lines
2140 let working_copy = gen_working_copy(rng, &head_text);2176 let working_copy = gen_working_copy(rng, &head_text);
2141 let working_copy = cx.new(|cx| {2177 let working_copy = cx.new(|cx| {
2142 language::Buffer::local_normalized(2178 language::Buffer::local_normalized(
2143 Rope::from(working_copy.as_str()),2179 Rope::from_str(working_copy.as_str(), cx.background_executor()),
2144 text::LineEnding::default(),2180 text::LineEnding::default(),
2145 cx,2181 cx,
2146 )2182 )
2147 });2183 });
2148 let working_copy = working_copy.read_with(cx, |working_copy, _| working_copy.snapshot());2184 let working_copy = working_copy.read_with(cx, |working_copy, _| working_copy.snapshot());
2149 let mut index_text = if rng.random() {2185 let mut index_text = if rng.random() {
2150 Rope::from(head_text.as_str())2186 Rope::from_str(head_text.as_str(), cx.background_executor())
2151 } else {2187 } else {
2152 working_copy.as_rope().clone()2188 working_copy.as_rope().clone()
2153 };2189 };