about summary refs log tree commit diff
path: root/library/std/src/sys/solid
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-26 02:19:08 +0000
committerbors <bors@rust-lang.org>2023-08-26 02:19:08 +0000
commit9334ec93541fd6963a3bfa2d2d09e3e33ac93131 (patch)
tree25ea50c55ad15b1f52b2ba178785ab3cefd8e7a5 /library/std/src/sys/solid
parentc5035271acc7e140893c1dcdb5a83bf4ddf04593 (diff)
parent1abaf40ec818dfc0a0ad50e6e772cce60acc8477 (diff)
Auto merge of #115228 - saethlin:is-interrupted, r=thomcc
Add a new helper to avoid calling io::Error::kind

On `cfg(unix)`, `Error::kind` emits an enormous jump table that LLVM seems unable to optimize out. I don't really understand why, but see for yourself: https://godbolt.org/z/17hY496KG

This change lets us check for `ErrorKind::Interrupted` without going through a big match. I've checked the codegen locally, and it has the desired effect on the codegen for `BufReader::read_exact`.
Diffstat (limited to 'library/std/src/sys/solid')
-rw-r--r--library/std/src/sys/solid/error.rs5
-rw-r--r--library/std/src/sys/solid/mod.rs5
-rw-r--r--library/std/src/sys/solid/net.rs6
3 files changed, 16 insertions, 0 deletions
diff --git a/library/std/src/sys/solid/error.rs b/library/std/src/sys/solid/error.rs
index 547b4f3a984..d1877a8bcd2 100644
--- a/library/std/src/sys/solid/error.rs
+++ b/library/std/src/sys/solid/error.rs
@@ -31,6 +31,11 @@ pub fn error_name(er: abi::ER) -> Option<&'static str> {
     }
 }
 
+#[inline]
+fn is_interrupted(er: abi::ER) -> bool {
+    false
+}
+
 pub fn decode_error_kind(er: abi::ER) -> ErrorKind {
     match er {
         // Success
diff --git a/library/std/src/sys/solid/mod.rs b/library/std/src/sys/solid/mod.rs
index 923d27fd936..e7029174511 100644
--- a/library/std/src/sys/solid/mod.rs
+++ b/library/std/src/sys/solid/mod.rs
@@ -72,6 +72,11 @@ pub fn unsupported_err() -> crate::io::Error {
     )
 }
 
+#[inline]
+pub fn is_interrupted(code: i32) -> bool {
+    error::is_interrupted(code)
+}
+
 pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind {
     error::decode_error_kind(code)
 }
diff --git a/library/std/src/sys/solid/net.rs b/library/std/src/sys/solid/net.rs
index 0bd2bc3b961..bdd64ab02b7 100644
--- a/library/std/src/sys/solid/net.rs
+++ b/library/std/src/sys/solid/net.rs
@@ -181,6 +181,12 @@ pub(super) fn error_name(er: abi::ER) -> Option<&'static str> {
     unsafe { CStr::from_ptr(netc::strerror(er)) }.to_str().ok()
 }
 
+#[inline]
+pub fn is_interrupted(er: abi::ER) -> bool {
+    let errno = netc::SOLID_NET_ERR_BASE - er;
+    errno as libc::c_int == libc::EINTR
+}
+
 pub(super) fn decode_error_kind(er: abi::ER) -> ErrorKind {
     let errno = netc::SOLID_NET_ERR_BASE - er;
     match errno as libc::c_int {