Skip to content

Commit c26ed87

Browse files
committed
type-erase actions ASAP to reduce monomorphization
The public API remains unchanged, but the closures are immediately converted to `Arc<dyn Fn(...)>` to avoid repeated monomorphization of `register_unchecked_impl`. Other `*_impl` functions get the same treatment for consistency, though they're much smaller.
1 parent ac4c81c commit c26ed87

File tree

1 file changed

+6
-13
lines changed
  • signal-hook-registry/src

1 file changed

+6
-13
lines changed

signal-hook-registry/src/lib.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ pub unsafe fn register<F>(signal: c_int, action: F) -> Result<SigId, Error>
542542
where
543543
F: Fn() + Sync + Send + 'static,
544544
{
545-
register_sigaction_impl(signal, move |_: &_| action())
545+
register_sigaction_impl(signal, Arc::new(move |_: &_| action()))
546546
}
547547

548548
/// Register a signal action.
@@ -559,13 +559,10 @@ pub unsafe fn register_sigaction<F>(signal: c_int, action: F) -> Result<SigId, E
559559
where
560560
F: Fn(&siginfo_t) + Sync + Send + 'static,
561561
{
562-
register_sigaction_impl(signal, action)
562+
register_sigaction_impl(signal, Arc::new(action))
563563
}
564564

565-
unsafe fn register_sigaction_impl<F>(signal: c_int, action: F) -> Result<SigId, Error>
566-
where
567-
F: Fn(&siginfo_t) + Sync + Send + 'static,
568-
{
565+
unsafe fn register_sigaction_impl(signal: c_int, action: Arc<Action>) -> Result<SigId, Error> {
569566
assert!(
570567
!FORBIDDEN.contains(&signal),
571568
"Attempted to register forbidden signal {}",
@@ -587,7 +584,7 @@ pub unsafe fn register_signal_unchecked<F>(signal: c_int, action: F) -> Result<S
587584
where
588585
F: Fn() + Sync + Send + 'static,
589586
{
590-
register_unchecked_impl(signal, move |_: &_| action())
587+
register_unchecked_impl(signal, Arc::new(move |_: &_| action()))
591588
}
592589

593590
/// Register a signal action without checking for forbidden signals.
@@ -608,15 +605,11 @@ pub unsafe fn register_unchecked<F>(signal: c_int, action: F) -> Result<SigId, E
608605
where
609606
F: Fn(&siginfo_t) + Sync + Send + 'static,
610607
{
611-
register_unchecked_impl(signal, action)
608+
register_unchecked_impl(signal, Arc::new(action))
612609
}
613610

614-
unsafe fn register_unchecked_impl<F>(signal: c_int, action: F) -> Result<SigId, Error>
615-
where
616-
F: Fn(&siginfo_t) + Sync + Send + 'static,
617-
{
611+
unsafe fn register_unchecked_impl(signal: c_int, action: Arc<Action>) -> Result<SigId, Error> {
618612
let globals = GlobalData::ensure();
619-
let action = Arc::from(action);
620613

621614
let mut lock = globals.data.write();
622615

0 commit comments

Comments
 (0)