Skip to content

Commit c960c3e

Browse files
authored
Rollup merge of #68102 - lzutao:inline, r=alexcrichton
Inline some conversion methods around OsStr Diff on the assembly of this snippet before and after this PR: https://www.diffchecker.com/NeGMjaJ2 ```rust use std::env; use std::io; use std::path::{Path, PathBuf}; pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result<PathBuf> { match env::var_os("CARGO_HOME").filter(|h| !h.is_empty()) { Some(home) => { let home = PathBuf::from(home); if home.is_absolute() { Ok(home) } else { Ok(cwd.join(&home)) } } _ => env::home_dir() .map(|p| p.join(".cargo")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), } } ```
2 parents cacda2d + 5f3f1a3 commit c960c3e

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

src/libstd/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {
250250
/// assert!(
251251
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
252252
/// ```
253+
#[inline]
253254
fn from(err: String) -> Box<dyn Error + Send + Sync> {
254255
struct StringError(String);
255256

@@ -317,6 +318,7 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
317318
/// assert!(
318319
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
319320
/// ```
321+
#[inline]
320322
fn from(err: &str) -> Box<dyn Error + Send + Sync + 'a> {
321323
From::from(String::from(err))
322324
}

src/libstd/ffi/os_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ impl OsStr {
615615
/// assert!(!os_str.is_empty());
616616
/// ```
617617
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
618+
#[inline]
618619
pub fn is_empty(&self) -> bool {
619620
self.inner.inner.is_empty()
620621
}
@@ -965,6 +966,7 @@ impl AsRef<OsStr> for OsStr {
965966

966967
#[stable(feature = "rust1", since = "1.0.0")]
967968
impl AsRef<OsStr> for OsString {
969+
#[inline]
968970
fn as_ref(&self) -> &OsStr {
969971
self
970972
}

src/libstd/path.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ impl From<OsString> for PathBuf {
14751475
/// Converts a `OsString` into a `PathBuf`
14761476
///
14771477
/// This conversion does not allocate or copy memory.
1478+
#[inline]
14781479
fn from(s: OsString) -> PathBuf {
14791480
PathBuf { inner: s }
14801481
}
@@ -1535,7 +1536,7 @@ impl fmt::Debug for PathBuf {
15351536
#[stable(feature = "rust1", since = "1.0.0")]
15361537
impl ops::Deref for PathBuf {
15371538
type Target = Path;
1538-
1539+
#[inline]
15391540
fn deref(&self) -> &Path {
15401541
Path::new(&self.inner)
15411542
}
@@ -2655,6 +2656,7 @@ impl AsRef<Path> for OsString {
26552656

26562657
#[stable(feature = "rust1", since = "1.0.0")]
26572658
impl AsRef<Path> for str {
2659+
#[inline]
26582660
fn as_ref(&self) -> &Path {
26592661
Path::new(self)
26602662
}
@@ -2669,6 +2671,7 @@ impl AsRef<Path> for String {
26692671

26702672
#[stable(feature = "rust1", since = "1.0.0")]
26712673
impl AsRef<Path> for PathBuf {
2674+
#[inline]
26722675
fn as_ref(&self) -> &Path {
26732676
self
26742677
}

src/libstd/sys_common/os_str_bytes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl Buf {
104104
self.inner.shrink_to(min_capacity)
105105
}
106106

107+
#[inline]
107108
pub fn as_slice(&self) -> &Slice {
108109
unsafe { mem::transmute(&*self.inner) }
109110
}

0 commit comments

Comments
 (0)