From 8f4ebfd2f7f120e6f50448509496614d7008aef3 Mon Sep 17 00:00:00 2001 From: Tim Vilgot Mikael Fredenberg <26655508+vilgotf@users.noreply.github.com> Date: Thu, 1 Jan 2026 22:18:29 +0100 Subject: [PATCH] signal: specialize unix `OsStorage` (#7818) --- tokio/src/signal/unix.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs index e70863b54..56bec97ff 100644 --- a/tokio/src/signal/unix.rs +++ b/tokio/src/signal/unix.rs @@ -18,21 +18,25 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Once; use std::task::{Context, Poll}; +#[cfg(not(any(target_os = "linux", target_os = "illumos")))] +pub(crate) type OsStorage = [SignalInfo; 34]; + +#[cfg(any(target_os = "linux", target_os = "illumos"))] pub(crate) type OsStorage = Box<[SignalInfo]>; impl Init for OsStorage { fn init() -> Self { // There are reliable signals ranging from 1 to 33 available on every Unix platform. #[cfg(not(any(target_os = "linux", target_os = "illumos")))] - let possible = 0..=33; + return std::array::from_fn(|_| SignalInfo::default()); // On Linux and illumos, there are additional real-time signals // available. (This is also likely true on Solaris, but this should be // verified before being enabled.) #[cfg(any(target_os = "linux", target_os = "illumos"))] - let possible = 0..=libc::SIGRTMAX(); - - possible.map(|_| SignalInfo::default()).collect() + return std::iter::repeat_with(SignalInfo::default) + .take(libc::SIGRTMAX() as usize + 1) + .collect(); } }