From e94ba4ae78bbca55b14967c05639a7bdf18bab26 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 18 Aug 2023 00:09:03 +0200 Subject: [PATCH] Inline strlen_rt in CStr::from_ptr This enables LLVM to optimize this function as if it was strlen without having to enable std-aware LTO. --- library/core/src/ffi/c_str.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 92e38df404980..163a65c909e45 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.