mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Avoid the overhead of select! when possible
This commit is contained in:
parent
9731fa9fe0
commit
d30711ae73
1 changed files with 6 additions and 3 deletions
|
@ -13,7 +13,7 @@ use std::{
|
|||
sync::atomic::AtomicUsize,
|
||||
};
|
||||
|
||||
use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
|
||||
use crossbeam_channel::{select, unbounded, Receiver, Sender};
|
||||
use notify::{Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
|
||||
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
||||
use rayon::iter::{IndexedParallelIterator as _, IntoParallelIterator as _, ParallelIterator};
|
||||
|
@ -85,10 +85,13 @@ impl NotifyActor {
|
|||
}
|
||||
|
||||
fn next_event(&self, receiver: &Receiver<Message>) -> Option<Event> {
|
||||
let watcher_receiver = self.watcher.as_ref().map(|(_, receiver)| receiver);
|
||||
let Some((_, watcher_receiver)) = &self.watcher else {
|
||||
return receiver.recv().ok().map(Event::Message);
|
||||
};
|
||||
|
||||
select! {
|
||||
recv(receiver) -> it => it.ok().map(Event::Message),
|
||||
recv(watcher_receiver.unwrap_or(&never())) -> it => Some(Event::NotifyEvent(it.unwrap())),
|
||||
recv(watcher_receiver) -> it => Some(Event::NotifyEvent(it.unwrap())),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue