Repository: alacritty/alacritty
File: alacritty/src/display/mod.rs (Rust)

Code before:
            let y = self.size_info.height() - damage_rect.y as f32 - height;
            let render_rect = RenderRect::new(x, y, width, height, DAMAGE_RECT_COLOR, 0.5);

            render_rects.push(render_rect);
        }
    }

    /// Requst a new frame for a window on Wayland.
    fn request_frame(&mut self, scheduler: &mut Scheduler) {
        // Mark that we've used a frame.
        self.window.has_frame.store(false, Ordering::Relaxed);

        #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
        if let Some(surface) = self.window.wayland_surface() {
            let has_frame = self.window.has_frame.clone();
            // Request a new frame.
            surface.frame().quick_assign(move |_, _, _| {
                has_frame.store(true, Ordering::Relaxed);
            });

            return;
        }

        // Get the display vblank interval in micro seconds.
        let monitor_vblank_interval = Duration::from_micros(
            (1e6 / (self
                .window
                .current_monitor()
                .and_then(|monitor| monitor.refresh_rate_millihertz())
                .unwrap_or(60_000) as f64
                / 1e3)) as u64,
        );

        let swap_delay = self.frame_timer_info.compute_delay(monitor_vblank_interval);

        let window_id = self.window.id();
        let timer_id = TimerId::new(Topic::Frame, window_id);
        let event = Event::new(EventType::Frame, window_id);

        scheduler.schedule(event, swap_delay, false, timer_id);
    }
}

impl Drop for Display {
    fn drop(&mut self) {
        // Switch OpenGL context before dropping, otherwise objects (like programs) from other
        // contexts might be deleted during droping renderer.
        self.make_current();
        unsafe {
            ManuallyDrop::drop(&mut self.renderer);
            ManuallyDrop::drop(&mut self.context);

Review comment (suggestion):
I find the `1e6` notation difficult to grasp at a glance and I rarely see that in source code likely for that reason. Sure it's shorter, but is it more readable than `1_000_000`?

If you go into the billions and higher it might be more helpful, but I think people will recognize much faster that `1_000_000` is a million rather than `1e6`.

This also applies to the `1e3` used later which is even worse since it's just 1000.

Code after:
    /// Highlight damaged rects.
    ///
    /// This function is for debug purposes only.
    fn highlight_damage(&self, render_rects: &mut Vec<RenderRect>) {
        for damage_rect in &self.damage_rects {
            let x = damage_rect.x as f32;
            let height = damage_rect.height as f32;
            let width = damage_rect.width as f32;
            let y = self.size_info.height() - damage_rect.y as f32 - height;
            let render_rect = RenderRect::new(x, y, width, height, DAMAGE_RECT_COLOR, 0.5);

            render_rects.push(render_rect);
        }
    }

    /// Requst a new frame for a window on Wayland.
    fn request_frame(&mut self, scheduler: &mut Scheduler) {
        // Mark that we've used a frame.
        self.window.has_frame.store(false, Ordering::Relaxed);

        #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
        if let Some(surface) = self.window.wayland_surface() {
            let has_frame = self.window.has_frame.clone();
            // Request a new frame.
            surface.frame().quick_assign(move |_, _, _| {
                has_frame.store(true, Ordering::Relaxed);
            });

            return;
        }

        // Get the display vblank interval.
        let monitor_vblank_interval = 1_000_000.
            / self
                .window
                .current_monitor()
                .and_then(|monitor| monitor.refresh_rate_millihertz())
                .unwrap_or(60_000) as f64;

        // Now convert it to micro seconds.
        let monitor_vblank_interval =
            Duration::from_micros((1000. * monitor_vblank_interval) as u64);

        let swap_timeout = self.frame_timer.compute_timeout(monitor_vblank_interval);

        let window_id = self.window.id();
        let timer_id = TimerId::new(Topic::Frame, window_id);
        let event = Event::new(EventType::Frame, window_id);

        scheduler.schedule(event, swap_timeout, false, timer_id);
    }