Skip to content

Commit 90b6c71

Browse files
authored
Rollup merge of #109682 - clubby789:c-str-inline, r=scottmcm
Add `#[inline]` to CStr trait implementations Fixes #109674 I noticed other usages of traits on `CStr` weren't being inlined, so also added hints to the other implementations
2 parents fceb3d4 + 901f108 commit 90b6c71

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/core/src/ffi/c_str.rs

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl fmt::Debug for CStr {
172172

173173
#[stable(feature = "cstr_default", since = "1.10.0")]
174174
impl Default for &CStr {
175+
#[inline]
175176
fn default() -> Self {
176177
const SLICE: &[c_char] = &[0];
177178
// SAFETY: `SLICE` is indeed pointing to a valid nul-terminated string.
@@ -623,6 +624,7 @@ impl CStr {
623624

624625
#[stable(feature = "rust1", since = "1.0.0")]
625626
impl PartialEq for CStr {
627+
#[inline]
626628
fn eq(&self, other: &CStr) -> bool {
627629
self.to_bytes().eq(other.to_bytes())
628630
}
@@ -631,12 +633,14 @@ impl PartialEq for CStr {
631633
impl Eq for CStr {}
632634
#[stable(feature = "rust1", since = "1.0.0")]
633635
impl PartialOrd for CStr {
636+
#[inline]
634637
fn partial_cmp(&self, other: &CStr) -> Option<Ordering> {
635638
self.to_bytes().partial_cmp(&other.to_bytes())
636639
}
637640
}
638641
#[stable(feature = "rust1", since = "1.0.0")]
639642
impl Ord for CStr {
643+
#[inline]
640644
fn cmp(&self, other: &CStr) -> Ordering {
641645
self.to_bytes().cmp(&other.to_bytes())
642646
}
@@ -646,6 +650,7 @@ impl Ord for CStr {
646650
impl ops::Index<ops::RangeFrom<usize>> for CStr {
647651
type Output = CStr;
648652

653+
#[inline]
649654
fn index(&self, index: ops::RangeFrom<usize>) -> &CStr {
650655
let bytes = self.to_bytes_with_nul();
651656
// we need to manually check the starting index to account for the null

0 commit comments

Comments
 (0)