diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-23 11:35:31 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-23 11:35:31 +0000 |
commit | 8a4c248c48ad7bb9ad556717ee013129c190dbfa (patch) | |
tree | d12e106a8fe4b2317d47f0ff727d34d4251fd2f8 /crates/ra_cargo_watch/src/lib.rs | |
parent | 2fb8a461225800ca605a9f2e997cd5e82fb37574 (diff) | |
parent | 05aa5b854b230c2f6ba182c0f2c94f3de9a47204 (diff) |
Merge #2898
2898: Remove RWLock from check watcher. r=matklad a=kiljacken
@matklad mentioned this might be a good idea.
So the general idea is that we don't really need the lock, as we can
just clone the check watcher state when creating a snapshot. We can then
use `Arc::get_mut` to get mutable access to the state from `WorldState`
when needed.
Running with this it seems to improve responsiveness a bit while cargo
is running, but I have no hard numbers to prove it. In any case, a
serialization point less is always better when we're trying to be
responsive.
Co-authored-by: Emil Lauridsen <[email protected]>
Diffstat (limited to 'crates/ra_cargo_watch/src/lib.rs')
-rw-r--r-- | crates/ra_cargo_watch/src/lib.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs index 7f4c9280c..bbe634603 100644 --- a/crates/ra_cargo_watch/src/lib.rs +++ b/crates/ra_cargo_watch/src/lib.rs | |||
@@ -7,7 +7,6 @@ use lsp_types::{ | |||
7 | Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd, | 7 | Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd, |
8 | WorkDoneProgressReport, | 8 | WorkDoneProgressReport, |
9 | }; | 9 | }; |
10 | use parking_lot::RwLock; | ||
11 | use std::{ | 10 | use std::{ |
12 | collections::HashMap, | 11 | collections::HashMap, |
13 | path::PathBuf, | 12 | path::PathBuf, |
@@ -38,7 +37,7 @@ pub struct CheckOptions { | |||
38 | #[derive(Debug)] | 37 | #[derive(Debug)] |
39 | pub struct CheckWatcher { | 38 | pub struct CheckWatcher { |
40 | pub task_recv: Receiver<CheckTask>, | 39 | pub task_recv: Receiver<CheckTask>, |
41 | pub state: Arc<RwLock<CheckState>>, | 40 | pub state: Arc<CheckState>, |
42 | cmd_send: Option<Sender<CheckCommand>>, | 41 | cmd_send: Option<Sender<CheckCommand>>, |
43 | handle: Option<JoinHandle<()>>, | 42 | handle: Option<JoinHandle<()>>, |
44 | } | 43 | } |
@@ -46,7 +45,7 @@ pub struct CheckWatcher { | |||
46 | impl CheckWatcher { | 45 | impl CheckWatcher { |
47 | pub fn new(options: &CheckOptions, workspace_root: PathBuf) -> CheckWatcher { | 46 | pub fn new(options: &CheckOptions, workspace_root: PathBuf) -> CheckWatcher { |
48 | let options = options.clone(); | 47 | let options = options.clone(); |
49 | let state = Arc::new(RwLock::new(CheckState::new())); | 48 | let state = Arc::new(CheckState::new()); |
50 | 49 | ||
51 | let (task_send, task_recv) = unbounded::<CheckTask>(); | 50 | let (task_send, task_recv) = unbounded::<CheckTask>(); |
52 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); | 51 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); |
@@ -59,7 +58,7 @@ impl CheckWatcher { | |||
59 | 58 | ||
60 | /// Returns a CheckWatcher that doesn't actually do anything | 59 | /// Returns a CheckWatcher that doesn't actually do anything |
61 | pub fn dummy() -> CheckWatcher { | 60 | pub fn dummy() -> CheckWatcher { |
62 | let state = Arc::new(RwLock::new(CheckState::new())); | 61 | let state = Arc::new(CheckState::new()); |
63 | CheckWatcher { task_recv: never(), cmd_send: None, handle: None, state } | 62 | CheckWatcher { task_recv: never(), cmd_send: None, handle: None, state } |
64 | } | 63 | } |
65 | 64 | ||
@@ -87,7 +86,7 @@ impl std::ops::Drop for CheckWatcher { | |||
87 | } | 86 | } |
88 | } | 87 | } |
89 | 88 | ||
90 | #[derive(Debug)] | 89 | #[derive(Clone, Debug)] |
91 | pub struct CheckState { | 90 | pub struct CheckState { |
92 | diagnostic_collection: HashMap<Url, Vec<Diagnostic>>, | 91 | diagnostic_collection: HashMap<Url, Vec<Diagnostic>>, |
93 | suggested_fix_collection: HashMap<Url, Vec<SuggestedFix>>, | 92 | suggested_fix_collection: HashMap<Url, Vec<SuggestedFix>>, |