From a522cfe7a8a6fc209208142ea83fd2368a4e4b6b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sun, 3 Jul 2022 22:39:59 -0700 Subject: [PATCH] Optimize away a call to `std::io::stdout()`. Previously, this code called `std::io::stdout` just to call `as_raw_fd` on it. But calling `std::io::stdout` involves acquiring a lock, and it doesn't fully optimize away. So instead, call `rustix::io::raw_stdout`, which just returns the stdout file descriptor directly, without taking a lock. --- Cargo.toml | 2 +- src/unix.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index be9d579..4a89cf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6", features = ["termios"] } +rustix = { version = "0.35.7", features = ["termios"] } [target.'cfg(windows)'.dependencies.windows-sys] version = "0.36.0" diff --git a/src/unix.rs b/src/unix.rs index ddc2fa8..59af979 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -1,12 +1,12 @@ use super::{Height, Width}; use std::os::unix::io::RawFd; -use rustix::fd::{BorrowedFd, AsRawFd}; +use rustix::fd::BorrowedFd; /// Returns the size of the terminal defaulting to STDOUT, if available. /// /// If STDOUT is not a tty, returns `None` pub fn terminal_size() -> Option<(Width, Height)> { - terminal_size_using_fd(std::io::stdout().as_raw_fd()) + terminal_size_using_fd(rustix::io::raw_stdout()) } /// Returns the size of the terminal using the given file descriptor, if available.