Skip to content

Commit

Permalink
Inline strlen_rt in CStr::from_ptr
Browse files Browse the repository at this point in the history
This enables LLVM to optimize this function as if it was strlen
without having to enable std-aware LTO.
  • Loading branch information
KamilaBorowska committed Aug 18, 2023
1 parent 0768872 commit e94ba4a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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.
Expand Down

0 comments on commit e94ba4a

Please sign in to comment.