From ca9ba5ca35a0be6f46dd028b1a7ef754bf3d2f84 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Fri, 20 Feb 2026 08:18:27 -0600 Subject: [PATCH] Remove extra allocation when copying to ComBuffer from &[u8] --- .../desktop_native/win_webauthn/src/plugin/com.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs b/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs index a7c64c7fbcc..789c820f6b1 100644 --- a/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs +++ b/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs @@ -440,19 +440,15 @@ impl ComBufferExt for &[u16] { impl> From for ComBuffer { fn from(value: T) -> Self { - let buffer: Vec = value - .as_ref() - .iter() - .flat_map(|x| x.to_le_bytes()) - .collect(); - let len = buffer.len(); + let slice = value.as_ref(); + let len = slice.len(); let com_buffer = Self::alloc(len, true); // SAFETY: `ptr` points to a valid allocation that `len` matches, and we made sure // the bytes were initialized. Additionally, bytes have no alignment requirements. unsafe { NonNull::slice_from_raw_parts(com_buffer.0.cast::(), len) .as_mut() - .copy_from_slice(&buffer); + .copy_from_slice(slice); } com_buffer }