From 99d163d20a52b1c79ae0c673119f4a8d51d01147 Mon Sep 17 00:00:00 2001 From: Arijit Dey Date: Tue, 23 Apr 2024 20:03:19 +0530 Subject: [PATCH] perf(init): Stop polling for events Rather read events in a blocking fashion. This way we are not wasting on useless CPU cycles --- src/core/init.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/core/init.rs b/src/core/init.rs index bbd6039..e1c029d 100644 --- a/src/core/init.rs +++ b/src/core/init.rs @@ -336,28 +336,24 @@ fn event_reader( } } - if event::poll(std::time::Duration::from_millis(100)) - .map_err(|e| MinusError::HandleEvent(e.into()))? - { - let ev = event::read().map_err(|e| MinusError::HandleEvent(e.into()))?; - let mut guard = ps.lock(); - // Get the events - let input = guard.input_classifier.classify_input(ev, &guard); - if let Some(iev) = input { - if let InputEvent::Number(n) = iev { - guard.prefix_num.push(n); - guard.format_prompt(); - } else if !guard.prefix_num.is_empty() { - guard.prefix_num.clear(); - guard.format_prompt(); - } - if let Err(TrySendError::Disconnected(_)) = evtx.try_send(Command::UserInput(iev)) { - break; - } + let ev = event::read().map_err(|e| MinusError::HandleEvent(e.into()))?; + let mut guard = ps.lock(); + // Get the events + let input = guard.input_classifier.classify_input(ev, &guard); + if let Some(iev) = input { + if let InputEvent::Number(n) = iev { + guard.prefix_num.push(n); + guard.format_prompt(); } else if !guard.prefix_num.is_empty() { guard.prefix_num.clear(); guard.format_prompt(); } + if let Err(TrySendError::Disconnected(_)) = evtx.try_send(Command::UserInput(iev)) { + break; + } + } else if !guard.prefix_num.is_empty() { + guard.prefix_num.clear(); + guard.format_prompt(); } } Result::<(), MinusError>::Ok(())