From c12c7b82e8224ee00e9c8538771f62d7046ea121 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 24 Dec 2023 19:27:02 +0100 Subject: [PATCH] On X11, simplify available_monitors() impl This code confused me. I tried to understand it. I tried to simplify it while keeping the functional style. But in the end, this just seems too complicated for its own good. Just doing the exact same thing with a match statement and the question mark operator makes it sooo much more obvious what is happening. Signed-off-by: Uli Schlachter --- src/platform_impl/linux/x11/monitor.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 9269f49ebc..a44e5458cb 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -284,22 +284,16 @@ impl XConnection { pub fn available_monitors(&self) -> Result, X11Error> { let mut monitors_lock = self.monitor_handles.lock().unwrap(); - (*monitors_lock) - .as_ref() - .cloned() - .map(Ok) - .or_else(|| { - self.query_monitor_list() - .map(|mon_list| { - let monitors = Some(mon_list); - if !DISABLE_MONITOR_LIST_CACHING { - (*monitors_lock) = monitors.clone(); - } - monitors - }) - .transpose() - }) - .unwrap() + match *monitors_lock { + Some(ref monitors) => Ok(monitors.clone()), + None => { + let monitors = self.query_monitor_list()?; + if !DISABLE_MONITOR_LIST_CACHING { + *monitors_lock = Some(monitors.clone()); + } + Ok(monitors) + } + } } #[inline]