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 @@
11 use futures::channel::oneshot;
22 use git2::{DiffLineType as GitDiffLineType, DiffOptions as GitOptions, Patch as GitPatch};
3−use gpui::{App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, Task, TaskLabel};
3+use gpui::{
4+ App, AppContext as _, AsyncApp, BackgroundExecutor, Context, Entity, EventEmitter, Task,
5+ TaskLabel,
6+};
47 use language::{Language, LanguageRegistry};
58 use rope::Rope;
69 use std::{
@@ -191,7 +194,7 @@ impl BufferDiffSnapshot { · 184 unmodified lines
191194 let base_text_exists;
192195 let base_text_snapshot;
193196 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());
195198 base_text_pair = Some((text.clone(), base_text_rope.clone()));
196199 let snapshot =
197200 language::Buffer::build_snapshot(base_text_rope, language, language_registry, cx);
@@ -311,6 +314,7 @@ impl BufferDiffInner { · 113 unmodified lines
311314 hunks: &[DiffHunk],
312315 buffer: &text::BufferSnapshot,
313316 file_exists: bool,
317+ cx: &BackgroundExecutor,
314318 ) -> Option<Rope> {
315319 let head_text = self
316320 .base_text_exists
@@ -505,7 +509,7 @@ impl BufferDiffInner { · 188 unmodified lines
505509 for (old_range, replacement_text) in edits {
506510 new_index_text.append(index_cursor.slice(old_range.start));
507511 index_cursor.seek_forward(old_range.end);
508− new_index_text.push(&replacement_text);
512+ new_index_text.push(&replacement_text, cx);
509513 }
510514 new_index_text.append(index_cursor.suffix());
511515 Some(new_index_text)
@@ -962,6 +966,7 @@ impl BufferDiff { · 450 unmodified lines
962966 hunks,
963967 buffer,
964968 file_exists,
969+ cx.background_executor(),
965970 );
966971
967972 cx.emit(BufferDiffEvent::HunksStagedOrUnstaged(
@@ -1385,7 +1390,12 @@ mod tests { · 417 unmodified lines
13851390 "
13861391 .unindent();
13871392
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+ );
13891399 let mut diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx);
13901400 assert_hunks(
13911401 diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer),
@@ -1394,7 +1404,7 @@ mod tests { · 2 unmodified lines
13941404 &[(1..2, "two\n", "HELLO\n", DiffHunkStatus::modified_none())],
13951405 );
13961406
1397− buffer.edit([(0..0, "point five\n")]);
1407+ buffer.edit([(0..0, "point five\n")], cx.background_executor());
13981408 diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx);
13991409 assert_hunks(
14001410 diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer),
@@ -1459,7 +1469,12 @@ mod tests { · 58 unmodified lines
14591469 "
14601470 .unindent();
14611471
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+ );
14631478 let unstaged_diff = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx);
14641479 let mut uncommitted_diff =
14651480 BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx);
@@ -1528,7 +1543,12 @@ mod tests { · 62 unmodified lines
15281543 "
15291544 .unindent();
15301545
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+ );
15321552 let diff = cx
15331553 .update(|cx| {
15341554 BufferDiffSnapshot::new_with_base_text(
@@ -1791,7 +1811,12 @@ mod tests { · 256 unmodified lines
17911811
17921812 for example in table {
17931813 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+ );
17951820 let hunk_range =
17961821 buffer.anchor_before(ranges[0].start)..buffer.anchor_before(ranges[0].end);
17971822
@@ -1868,6 +1893,7 @@ mod tests { · 70 unmodified lines
18681893 ReplicaId::LOCAL,
18691894 BufferId::new(1).unwrap(),
18701895 buffer_text.clone(),
1896+ cx.background_executor(),
18711897 );
18721898 let unstaged = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx);
18731899 let uncommitted = BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx);
@@ -1941,7 +1967,12 @@ mod tests { · 67 unmodified lines
19411967 "
19421968 .unindent();
19431969
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+ );
19451976
19461977 let empty_diff = cx.update(|cx| BufferDiffSnapshot::empty(&buffer, cx));
19471978 let diff_1 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
@@ -1961,6 +1992,7 @@ mod tests { · 13 unmodified lines
19611992 NINE
19621993 "
19631994 .unindent(),
1995+ cx.background_executor(),
19641996 );
19651997 let diff_2 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
19661998 assert_eq!(None, diff_2.inner.compare(&diff_1.inner, &buffer));
@@ -1978,6 +2010,7 @@ mod tests { · 11 unmodified lines
19782010 NINE
19792011 "
19802012 .unindent(),
2013+ cx.background_executor(),
19812014 );
19822015 let diff_3 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
19832016 let range = diff_3.inner.compare(&diff_2.inner, &buffer).unwrap();
@@ -1995,6 +2028,7 @@ mod tests { · 11 unmodified lines
19952028 NINE
19962029 "
19972030 .unindent(),
2031+ cx.background_executor(),
19982032 );
19992033 let diff_4 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx);
20002034 let range = diff_4.inner.compare(&diff_3.inner, &buffer).unwrap();
@@ -2013,6 +2047,7 @@ mod tests { · 12 unmodified lines
20132047 NINE
20142048 "
20152049 .unindent(),
2050+ cx.background_executor(),
20162051 );
20172052 let diff_5 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text.clone(), cx);
20182053 let range = diff_5.inner.compare(&diff_4.inner, &buffer).unwrap();
@@ -2031,6 +2066,7 @@ mod tests { · 12 unmodified lines
20312066 «nine»
20322067 "
20332068 .unindent(),
2069+ cx.background_executor(),
20342070 );
20352071 let diff_6 = BufferDiffSnapshot::new_sync(buffer.snapshot(), base_text, cx);
20362072 let range = diff_6.inner.compare(&diff_5.inner, &buffer).unwrap();
@@ -2140,14 +2176,14 @@ mod tests { · 103 unmodified lines
21402176 let working_copy = gen_working_copy(rng, &head_text);
21412177 let working_copy = cx.new(|cx| {
21422178 language::Buffer::local_normalized(
2143− Rope::from(working_copy.as_str()),
2179+ Rope::from_str(working_copy.as_str(), cx.background_executor()),
21442180 text::LineEnding::default(),
21452181 cx,
21462182 )
21472183 });
21482184 let working_copy = working_copy.read_with(cx, |working_copy, _| working_copy.snapshot());
21492185 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())
21512187 } else {
21522188 working_copy.as_rope().clone()
21532189 };