Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline some conversion methods around OsStr #68102

Merged
merged 7 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {
/// assert!(
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
/// ```
#[inline]
fn from(err: String) -> Box<dyn Error + Send + Sync> {
struct StringError(String);

Expand Down Expand Up @@ -317,6 +318,7 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
/// assert!(
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
/// ```
#[inline]
fn from(err: &str) -> Box<dyn Error + Send + Sync + 'a> {
From::from(String::from(err))
}
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ impl OsStr {
/// assert!(!os_str.is_empty());
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn is_empty(&self) -> bool {
self.inner.inner.is_empty()
}
Expand Down Expand Up @@ -965,6 +966,7 @@ impl AsRef<OsStr> for OsStr {

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for OsString {
#[inline]
fn as_ref(&self) -> &OsStr {
self
}
Expand Down
5 changes: 4 additions & 1 deletion src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,7 @@ impl From<OsString> for PathBuf {
/// Converts a `OsString` into a `PathBuf`
///
/// This conversion does not allocate or copy memory.
#[inline]
fn from(s: OsString) -> PathBuf {
PathBuf { inner: s }
}
Expand Down Expand Up @@ -1535,7 +1536,7 @@ impl fmt::Debug for PathBuf {
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Deref for PathBuf {
type Target = Path;

#[inline]
fn deref(&self) -> &Path {
Path::new(&self.inner)
}
Expand Down Expand Up @@ -2655,6 +2656,7 @@ impl AsRef<Path> for OsString {

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

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for PathBuf {
#[inline]
fn as_ref(&self) -> &Path {
self
}
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys_common/os_str_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl Buf {
self.inner.shrink_to(min_capacity)
}

#[inline]
pub fn as_slice(&self) -> &Slice {
unsafe { mem::transmute(&*self.inner) }
}
Expand Down