From 0b75a7169b2e123cac04e7ffcaf16a28eb356fd0 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sat, 4 Nov 2023 05:00:12 -0700 Subject: perf: lazy `atexit` setup (#21053) `libc::atexit` incurrs 2% dyld cost at startup on macOS. This PR moves the setup to when the tty mode is changed using op_stdin_set_raw. --- cli/util/unix.rs | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'cli/util/unix.rs') diff --git a/cli/util/unix.rs b/cli/util/unix.rs index 2fa3c2063..fd0c94ea6 100644 --- a/cli/util/unix.rs +++ b/cli/util/unix.rs @@ -43,27 +43,3 @@ pub fn raise_fd_limit() { } } } - -pub fn prepare_stdio() { - #[cfg(unix)] - // SAFETY: Save current state of stdio and restore it when we exit. - unsafe { - use libc::atexit; - use libc::tcgetattr; - use libc::tcsetattr; - use libc::termios; - - let mut termios = std::mem::zeroed::(); - if tcgetattr(libc::STDIN_FILENO, &mut termios) == 0 { - static mut ORIG_TERMIOS: Option = None; - ORIG_TERMIOS = Some(termios); - - extern "C" fn reset_stdio() { - // SAFETY: Reset the stdio state. - unsafe { tcsetattr(libc::STDIN_FILENO, 0, &ORIG_TERMIOS.unwrap()) }; - } - - atexit(reset_stdio); - } - } -} -- cgit v1.2.3