Skip to content

Commit e94ba4a

Browse files
committed
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.
1 parent 0768872 commit e94ba4a

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)