diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-20 00:28:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-20 00:28:31 +0200 |
| commit | cad8f8cbffc2247e95d27111b4683afe723a549a (patch) | |
| tree | 2471f0f5f6cb6c8c28208072603e770fb89f67d2 | |
| parent | 03455c889594cccd91a44e19566254617dec0f81 (diff) | |
| parent | e94ba4ae78bbca55b14967c05639a7bdf18bab26 (diff) | |
| download | rust-cad8f8cbffc2247e95d27111b4683afe723a549a.tar.gz rust-cad8f8cbffc2247e95d27111b4683afe723a549a.zip | |
Rollup merge of #114950 - xfix:inline-cstr-from-ptr, r=cuviper
Inline strlen_rt in CStr::from_ptr This enables LLVM to optimize this function as if it was strlen (LLVM knows what it does, and can avoid calling it in certain situations) without having to enable std-aware LTO. This is essentially doing what https://github.com/rust-lang/rust/pull/90007 did, except updated for this function being `const`. Pretty sure it's safe to roll-up, considering last time I did make this change it didn't affect performance (`CStr::from_ptr` isn't really used all that often in Rust code that is checked by rust-perf).
| -rw-r--r-- | library/core/src/ffi/c_str.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 92e38df4049..163a65c909e 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -253,7 +253,7 @@ impl CStr { /// ``` /// /// [valid]: core::ptr#safety - #[inline] + #[inline] // inline is necessary for codegen to see strlen. #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_cstr_from_ptr", issue = "113219")] @@ -280,6 +280,8 @@ impl CStr { len } + // `inline` is necessary for codegen to see strlen. + #[inline] fn strlen_rt(s: *const c_char) -> usize { extern "C" { /// Provided by libc or compiler_builtins. |
