Skip to content

Commit fbaf434

Browse files
authored
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 #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).
2 parents f86c163 + e94ba4a commit fbaf434

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/core/src/ffi/c_str.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl CStr {
253253
/// ```
254254
///
255255
/// [valid]: core::ptr#safety
256-
#[inline]
256+
#[inline] // inline is necessary for codegen to see strlen.
257257
#[must_use]
258258
#[stable(feature = "rust1", since = "1.0.0")]
259259
#[rustc_const_unstable(feature = "const_cstr_from_ptr", issue = "113219")]
@@ -280,6 +280,8 @@ impl CStr {
280280
len
281281
}
282282

283+
// `inline` is necessary for codegen to see strlen.
284+
#[inline]
283285
fn strlen_rt(s: *const c_char) -> usize {
284286
extern "C" {
285287
/// Provided by libc or compiler_builtins.

0 commit comments

Comments
 (0)