Repository: alacritty/alacritty
File: alacritty/src/event.rs (Rust)

Code before:
    where
        T: EventListener,
    {
        let mut event_queue = Vec::new();

        event_loop.run_return(|event, event_loop, control_flow| {
            if self.config.debug.print_events {
                info!("glutin event: {:?}", event);
            }

            // Ignore all events we do not care about
            if Self::skip_event(&event) {
                return;
            }

            match event {
                // Check for shutdown
                GlutinEvent::UserEvent(Event::Exit) => {
                    *control_flow = ControlFlow::Exit;
                    return;
                },
                // Process events
                GlutinEvent::RedrawEventsCleared => {
                    *control_flow = ControlFlow::Wait;

                    let event_queue_empty = event_queue.is_empty();

                    #[cfg(not(any(target_os = "macos", windows)))]
                    {
                        let wayland_queue_empty = if event_loop.is_wayland() {
                            let num_dispatched = self
                                .display
                                .wayland_event_queue
                                .as_mut()
                                .unwrap()
                                .dispatch_pending(&mut (), |_, _, _| {})
                                .unwrap();
                            num_dispatched == 0
                        } else {
                            true
                        };

                        if event_queue_empty && wayland_queue_empty {
                            return;
                        }
                    }
                    #[cfg(any(target_os = "macos", windows))]
                    {
                        if event_queue_empty {
                            return;
                        }

Review comment (refactor):
Seems like there's no need to extract this as a variable? Since it's just conditionally compiled in, it's not executed twice at runtime anyways.

Code after:
    /// Return `true` if `event_queue` is empty, `false` otherwise.
    #[inline]
    #[cfg(not(any(target_os = "macos", windows)))]
    fn event_queue_empty(&mut self) -> bool {
        let wayland_event_queue = match self.display.wayland_event_queue.as_mut() {
            Some(wayland_event_queue) => wayland_event_queue,
            // Since frame callbacks do not exist on X11, just check for event queue.
            None => return self.event_queue.is_empty(),
        };

        // Check for pending frame callbacks on Wayland.
        let events_dispatched = wayland_event_queue
            .dispatch_pending(&mut (), |_, _, _| {})
            .expect("failed to dispatch event queue");

        self.event_queue.is_empty() && events_dispatched == 0
    }

    /// Return `true` if `event_queue` is empty, `false` otherwise.
    #[inline]
    #[cfg(any(target_os = "macos", windows))]
    fn event_queue_empty(&mut self) -> bool {
        self.event_queue.is_empty()
    }

    /// Run the event loop.
    pub fn run<T>(&mut self, terminal: Arc<FairMutex<Term<T>>>, mut event_loop: EventLoop<Event>)
    where
        T: EventListener,
    {
        event_loop.run_return(|event, event_loop, control_flow| {
            if self.config.debug.print_events {
                info!("glutin event: {:?}", event);
            }

            // Ignore all events we do not care about.
            if Self::skip_event(&event) {
                return;
            }

            match event {
                // Check for shutdown.
                GlutinEvent::UserEvent(Event::Exit) => {
                    *control_flow = ControlFlow::Exit;
                    return;
                },
                // Process events.
                GlutinEvent::RedrawEventsCleared => {
                    *control_flow = ControlFlow::Wait;

                    if self.event_queue_empty() {