Skip to content

Commit c255815

Browse files
authored
Rollup merge of #67169 - lzutao:inline_osstr, r=nagisa
inline some common methods on OsStr Closes #67150
2 parents 196ca9d + bf1f1c2 commit c255815

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/libstd/ffi/os_str.rs

+8
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,13 @@ impl OsStr {
495495
///
496496
/// let os_str = OsStr::new("foo");
497497
/// ```
498+
#[inline]
498499
#[stable(feature = "rust1", since = "1.0.0")]
499500
pub fn new<S: AsRef<OsStr> + ?Sized>(s: &S) -> &OsStr {
500501
s.as_ref()
501502
}
502503

504+
#[inline]
503505
fn from_inner(inner: &Slice) -> &OsStr {
504506
unsafe { &*(inner as *const Slice as *const OsStr) }
505507
}
@@ -658,6 +660,7 @@ impl OsStr {
658660
///
659661
/// Note: it is *crucial* that this API is private, to avoid
660662
/// revealing the internal, platform-specific encodings.
663+
#[inline]
661664
fn bytes(&self) -> &[u8] {
662665
unsafe { &*(&self.inner as *const _ as *const [u8]) }
663666
}
@@ -797,20 +800,23 @@ impl Default for &OsStr {
797800

798801
#[stable(feature = "rust1", since = "1.0.0")]
799802
impl PartialEq for OsStr {
803+
#[inline]
800804
fn eq(&self, other: &OsStr) -> bool {
801805
self.bytes().eq(other.bytes())
802806
}
803807
}
804808

805809
#[stable(feature = "rust1", since = "1.0.0")]
806810
impl PartialEq<str> for OsStr {
811+
#[inline]
807812
fn eq(&self, other: &str) -> bool {
808813
*self == *OsStr::new(other)
809814
}
810815
}
811816

812817
#[stable(feature = "rust1", since = "1.0.0")]
813818
impl PartialEq<OsStr> for str {
819+
#[inline]
814820
fn eq(&self, other: &OsStr) -> bool {
815821
*other == *OsStr::new(self)
816822
}
@@ -944,13 +950,15 @@ impl AsRef<OsStr> for OsString {
944950

945951
#[stable(feature = "rust1", since = "1.0.0")]
946952
impl AsRef<OsStr> for str {
953+
#[inline]
947954
fn as_ref(&self) -> &OsStr {
948955
OsStr::from_inner(Slice::from_str(self))
949956
}
950957
}
951958

952959
#[stable(feature = "rust1", since = "1.0.0")]
953960
impl AsRef<OsStr> for String {
961+
#[inline]
954962
fn as_ref(&self) -> &OsStr {
955963
(&**self).as_ref()
956964
}

src/libstd/sys/windows/os_str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl Buf {
128128
}
129129

130130
impl Slice {
131+
#[inline]
131132
pub fn from_str(s: &str) -> &Slice {
132133
unsafe { mem::transmute(Wtf8::from_str(s)) }
133134
}

src/libstd/sys_common/os_str_bytes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ impl Buf {
139139
}
140140

141141
impl Slice {
142+
#[inline]
142143
fn from_u8_slice(s: &[u8]) -> &Slice {
143144
unsafe { mem::transmute(s) }
144145
}
145146

147+
#[inline]
146148
pub fn from_str(s: &str) -> &Slice {
147149
Slice::from_u8_slice(s.as_bytes())
148150
}

0 commit comments

Comments
 (0)