about summary refs log tree commit diff
path: root/library/std/src/sys/unix/fs.rs
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-05-01 17:10:25 +0200
committerGitHub <noreply@github.com>2023-05-01 17:10:25 +0200
commit02134611cefa7c0d45503c91375653af216a40bc (patch)
tree5037496dd39f48c4b8270edb6e53e567bc097913 /library/std/src/sys/unix/fs.rs
parent0a2562bf4de82b897beacf788e153f5738458325 (diff)
parent500a8e13361787ad24c9ee88f8345d853ff628d3 (diff)
downloadrust-02134611cefa7c0d45503c91375653af216a40bc.tar.gz
rust-02134611cefa7c0d45503c91375653af216a40bc.zip
Rollup merge of #111057 - xfix:tcpstream-as-raw-fd-inline, r=m-ou-se
Make sure the implementation of TcpStream::as_raw_fd is fully inlined

Currently the following function:

```rust
use std::os::fd::{AsRawFd, RawFd};
use std::net::TcpStream;

pub fn as_raw_fd(socket: &TcpStream) -> RawFd {
    socket.as_raw_fd()
}
```

Is optimized to the following:

```asm
example::as_raw_fd:
        push    rax
        call    qword ptr [rip + <std::net::tcp::TcpStream as std::sys_common::AsInner<std::sys_common::net::TcpStream>>::as_inner@GOTPCREL]
        mov     rdi, rax
        call    qword ptr [rip + std::sys_common::net::TcpStream::socket@GOTPCREL]
        mov     rdi, rax
        pop     rax
        jmp     qword ptr [rip + _ZN73_$LT$std..sys..unix..net..Socket$u20$as$u20$std..os..fd..raw..AsRawFd$GT$9as_raw_fd17h633bcf7e481df8bbE@GOTPCREL]
```

I think it would make more sense to inline trivial functions used within `TcpStream::AsRawFd`.
Diffstat (limited to 'library/std/src/sys/unix/fs.rs')
-rw-r--r--library/std/src/sys/unix/fs.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 2a5a14209a1..b398fd5eb24 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -547,6 +547,7 @@ impl FileAttr {
 }
 
 impl AsInner<stat64> for FileAttr {
+    #[inline]
     fn as_inner(&self) -> &stat64 {
         &self.stat
     }
@@ -1269,12 +1270,14 @@ impl DirBuilder {
 }
 
 impl AsInner<FileDesc> for File {
+    #[inline]
     fn as_inner(&self) -> &FileDesc {
         &self.0
     }
 }
 
 impl AsInnerMut<FileDesc> for File {
+    #[inline]
     fn as_inner_mut(&mut self) -> &mut FileDesc {
         &mut self.0
     }
@@ -1299,6 +1302,7 @@ impl AsFd for File {
 }
 
 impl AsRawFd for File {
+    #[inline]
     fn as_raw_fd(&self) -> RawFd {
         self.0.as_raw_fd()
     }