Skip to content

Commit 9880560

Browse files
committed
Inline methods of Path and OsString
1 parent bbc01bb commit 9880560

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

library/std/src/ffi/os_str.rs

+34
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl OsString {
111111
/// let os_string = OsString::new();
112112
/// ```
113113
#[stable(feature = "rust1", since = "1.0.0")]
114+
#[inline]
114115
pub fn new() -> OsString {
115116
OsString { inner: Buf::from_string(String::new()) }
116117
}
@@ -127,6 +128,7 @@ impl OsString {
127128
/// assert_eq!(os_string.as_os_str(), os_str);
128129
/// ```
129130
#[stable(feature = "rust1", since = "1.0.0")]
131+
#[inline]
130132
pub fn as_os_str(&self) -> &OsStr {
131133
self
132134
}
@@ -145,6 +147,7 @@ impl OsString {
145147
/// assert_eq!(string, Ok(String::from("foo")));
146148
/// ```
147149
#[stable(feature = "rust1", since = "1.0.0")]
150+
#[inline]
148151
pub fn into_string(self) -> Result<String, OsString> {
149152
self.inner.into_string().map_err(|buf| OsString { inner: buf })
150153
}
@@ -163,6 +166,7 @@ impl OsString {
163166
/// assert_eq!(&os_string, "foobar");
164167
/// ```
165168
#[stable(feature = "rust1", since = "1.0.0")]
169+
#[inline]
166170
pub fn push<T: AsRef<OsStr>>(&mut self, s: T) {
167171
self.inner.push_slice(&s.as_ref().inner)
168172
}
@@ -189,6 +193,7 @@ impl OsString {
189193
/// assert_eq!(capacity, os_string.capacity());
190194
/// ```
191195
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
196+
#[inline]
192197
pub fn with_capacity(capacity: usize) -> OsString {
193198
OsString { inner: Buf::with_capacity(capacity) }
194199
}
@@ -207,6 +212,7 @@ impl OsString {
207212
/// assert_eq!(&os_string, "");
208213
/// ```
209214
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
215+
#[inline]
210216
pub fn clear(&mut self) {
211217
self.inner.clear()
212218
}
@@ -224,6 +230,7 @@ impl OsString {
224230
/// assert!(os_string.capacity() >= 10);
225231
/// ```
226232
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
233+
#[inline]
227234
pub fn capacity(&self) -> usize {
228235
self.inner.capacity()
229236
}
@@ -243,6 +250,7 @@ impl OsString {
243250
/// assert!(s.capacity() >= 10);
244251
/// ```
245252
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
253+
#[inline]
246254
pub fn reserve(&mut self, additional: usize) {
247255
self.inner.reserve(additional)
248256
}
@@ -265,6 +273,7 @@ impl OsString {
265273
/// assert!(s.capacity() >= 10);
266274
/// ```
267275
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
276+
#[inline]
268277
pub fn reserve_exact(&mut self, additional: usize) {
269278
self.inner.reserve_exact(additional)
270279
}
@@ -285,6 +294,7 @@ impl OsString {
285294
/// assert_eq!(3, s.capacity());
286295
/// ```
287296
#[stable(feature = "osstring_shrink_to_fit", since = "1.19.0")]
297+
#[inline]
288298
pub fn shrink_to_fit(&mut self) {
289299
self.inner.shrink_to_fit()
290300
}
@@ -342,6 +352,7 @@ impl From<String> for OsString {
342352
/// Converts a [`String`] into a [`OsString`].
343353
///
344354
/// The conversion copies the data, and includes an allocation on the heap.
355+
#[inline]
345356
fn from(s: String) -> OsString {
346357
OsString { inner: Buf::from_string(s) }
347358
}
@@ -408,34 +419,39 @@ impl fmt::Debug for OsString {
408419

409420
#[stable(feature = "rust1", since = "1.0.0")]
410421
impl PartialEq for OsString {
422+
#[inline]
411423
fn eq(&self, other: &OsString) -> bool {
412424
&**self == &**other
413425
}
414426
}
415427

416428
#[stable(feature = "rust1", since = "1.0.0")]
417429
impl PartialEq<str> for OsString {
430+
#[inline]
418431
fn eq(&self, other: &str) -> bool {
419432
&**self == other
420433
}
421434
}
422435

423436
#[stable(feature = "rust1", since = "1.0.0")]
424437
impl PartialEq<OsString> for str {
438+
#[inline]
425439
fn eq(&self, other: &OsString) -> bool {
426440
&**other == self
427441
}
428442
}
429443

430444
#[stable(feature = "os_str_str_ref_eq", since = "1.29.0")]
431445
impl PartialEq<&str> for OsString {
446+
#[inline]
432447
fn eq(&self, other: &&str) -> bool {
433448
**self == **other
434449
}
435450
}
436451

437452
#[stable(feature = "os_str_str_ref_eq", since = "1.29.0")]
438453
impl<'a> PartialEq<OsString> for &'a str {
454+
#[inline]
439455
fn eq(&self, other: &OsString) -> bool {
440456
**other == **self
441457
}
@@ -539,6 +555,7 @@ impl OsStr {
539555
/// assert_eq!(os_str.to_str(), Some("foo"));
540556
/// ```
541557
#[stable(feature = "rust1", since = "1.0.0")]
558+
#[inline]
542559
pub fn to_str(&self) -> Option<&str> {
543560
self.inner.to_str()
544561
}
@@ -589,6 +606,7 @@ impl OsStr {
589606
/// }
590607
/// ```
591608
#[stable(feature = "rust1", since = "1.0.0")]
609+
#[inline]
592610
pub fn to_string_lossy(&self) -> Cow<'_, str> {
593611
self.inner.to_string_lossy()
594612
}
@@ -605,6 +623,7 @@ impl OsStr {
605623
/// assert_eq!(os_string, OsString::from("foo"));
606624
/// ```
607625
#[stable(feature = "rust1", since = "1.0.0")]
626+
#[inline]
608627
pub fn to_os_string(&self) -> OsString {
609628
OsString { inner: self.inner.to_owned() }
610629
}
@@ -655,6 +674,7 @@ impl OsStr {
655674
/// ```
656675
#[doc(alias = "length")]
657676
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
677+
#[inline]
658678
pub fn len(&self) -> usize {
659679
self.inner.inner.len()
660680
}
@@ -696,6 +716,7 @@ impl OsStr {
696716
/// assert_eq!("grÜße, jÜrgen ❤", s);
697717
/// ```
698718
#[unstable(feature = "osstring_ascii", issue = "70516")]
719+
#[inline]
699720
pub fn make_ascii_lowercase(&mut self) {
700721
self.inner.make_ascii_lowercase()
701722
}
@@ -721,6 +742,7 @@ impl OsStr {
721742
/// assert_eq!("GRüßE, JüRGEN ❤", s);
722743
/// ```
723744
#[unstable(feature = "osstring_ascii", issue = "70516")]
745+
#[inline]
724746
pub fn make_ascii_uppercase(&mut self) {
725747
self.inner.make_ascii_uppercase()
726748
}
@@ -784,6 +806,7 @@ impl OsStr {
784806
/// assert!(!non_ascii.is_ascii());
785807
/// ```
786808
#[unstable(feature = "osstring_ascii", issue = "70516")]
809+
#[inline]
787810
pub fn is_ascii(&self) -> bool {
788811
self.inner.is_ascii()
789812
}
@@ -811,6 +834,7 @@ impl OsStr {
811834

812835
#[stable(feature = "box_from_os_str", since = "1.17.0")]
813836
impl From<&OsStr> for Box<OsStr> {
837+
#[inline]
814838
fn from(s: &OsStr) -> Box<OsStr> {
815839
let rw = Box::into_raw(s.inner.into_box()) as *mut OsStr;
816840
unsafe { Box::from_raw(rw) }
@@ -832,6 +856,7 @@ impl From<Cow<'_, OsStr>> for Box<OsStr> {
832856
impl From<Box<OsStr>> for OsString {
833857
/// Converts a [`Box`]`<`[`OsStr`]`>` into a `OsString` without copying or
834858
/// allocating.
859+
#[inline]
835860
fn from(boxed: Box<OsStr>) -> OsString {
836861
boxed.into_os_string()
837862
}
@@ -840,6 +865,7 @@ impl From<Box<OsStr>> for OsString {
840865
#[stable(feature = "box_from_os_string", since = "1.20.0")]
841866
impl From<OsString> for Box<OsStr> {
842867
/// Converts a [`OsString`] into a [`Box`]`<OsStr>` without copying or allocating.
868+
#[inline]
843869
fn from(s: OsString) -> Box<OsStr> {
844870
s.into_boxed_os_str()
845871
}
@@ -925,6 +951,7 @@ impl<'a> From<Cow<'a, OsStr>> for OsString {
925951

926952
#[stable(feature = "box_default_extra", since = "1.17.0")]
927953
impl Default for Box<OsStr> {
954+
#[inline]
928955
fn default() -> Box<OsStr> {
929956
let rw = Box::into_raw(Slice::empty_box()) as *mut OsStr;
930957
unsafe { Box::from_raw(rw) }
@@ -1075,6 +1102,7 @@ impl OsStr {
10751102

10761103
#[stable(feature = "rust1", since = "1.0.0")]
10771104
impl Borrow<OsStr> for OsString {
1105+
#[inline]
10781106
fn borrow(&self) -> &OsStr {
10791107
&self[..]
10801108
}
@@ -1083,16 +1111,19 @@ impl Borrow<OsStr> for OsString {
10831111
#[stable(feature = "rust1", since = "1.0.0")]
10841112
impl ToOwned for OsStr {
10851113
type Owned = OsString;
1114+
#[inline]
10861115
fn to_owned(&self) -> OsString {
10871116
self.to_os_string()
10881117
}
1118+
#[inline]
10891119
fn clone_into(&self, target: &mut OsString) {
10901120
self.inner.clone_into(&mut target.inner)
10911121
}
10921122
}
10931123

10941124
#[stable(feature = "rust1", since = "1.0.0")]
10951125
impl AsRef<OsStr> for OsStr {
1126+
#[inline]
10961127
fn as_ref(&self) -> &OsStr {
10971128
self
10981129
}
@@ -1123,12 +1154,14 @@ impl AsRef<OsStr> for String {
11231154
}
11241155

11251156
impl FromInner<Buf> for OsString {
1157+
#[inline]
11261158
fn from_inner(buf: Buf) -> OsString {
11271159
OsString { inner: buf }
11281160
}
11291161
}
11301162

11311163
impl IntoInner<Buf> for OsString {
1164+
#[inline]
11321165
fn into_inner(self) -> Buf {
11331166
self.inner
11341167
}
@@ -1145,6 +1178,7 @@ impl AsInner<Slice> for OsStr {
11451178
impl FromStr for OsString {
11461179
type Err = core::convert::Infallible;
11471180

1181+
#[inline]
11481182
fn from_str(s: &str) -> Result<Self, Self::Err> {
11491183
Ok(OsString::from(s))
11501184
}

0 commit comments

Comments
 (0)