From 8594e72d3118904dae94be007576f5c8b630c0a7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 26 May 2022 09:48:42 -0700 Subject: [PATCH] perf(logging): avoid extra heap allocations --- komorebi/src/window.rs | 9 +++++---- komorebi/src/winevent.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 4ecab9c1..b679cfde 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -1,6 +1,7 @@ use std::convert::TryFrom; use std::fmt::Display; use std::fmt::Formatter; +use std::fmt::Write as _; use color_eyre::eyre::anyhow; use color_eyre::Result; @@ -36,18 +37,18 @@ impl Display for Window { let mut display = format!("(hwnd: {}", self.hwnd); if let Ok(title) = self.title() { - display.push_str(&format!(", title: {}", title)); + write!(display, ", title: {}", title)?; } if let Ok(exe) = self.exe() { - display.push_str(&format!(", exe: {}", exe)); + write!(display, ", exe: {}", exe)?; } if let Ok(class) = self.class() { - display.push_str(&format!(", class: {}", class)); + write!(display, ", class: {}", class)?; } - display.push(')'); + write!(display, ")")?; write!(f, "{}", display) } diff --git a/komorebi/src/winevent.rs b/komorebi/src/winevent.rs index 62af825a..756a5580 100644 --- a/komorebi/src/winevent.rs +++ b/komorebi/src/winevent.rs @@ -88,7 +88,7 @@ use windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_EVENTID_START; use windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_PROPID_END; use windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_PROPID_START; -#[derive(Clone, Copy, PartialEq, Debug, Serialize, Display, JsonSchema)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Display, JsonSchema)] #[repr(u32)] #[allow(dead_code)] pub enum WinEvent {