From 137a31d6923f229ffb5ed78772d02ecda3c7c53c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 18:20:40 +0000 Subject: [PATCH 1/7] Inline to make OsStr::is_empty zero cost --- src/libstd/ffi/os_str.rs | 1 + src/libstd/sys_common/os_str_bytes.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 4c308327b83b7..ec2d07f34ca5f 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -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() } diff --git a/src/libstd/sys_common/os_str_bytes.rs b/src/libstd/sys_common/os_str_bytes.rs index eb8a881ec8881..e965ea79aa039 100644 --- a/src/libstd/sys_common/os_str_bytes.rs +++ b/src/libstd/sys_common/os_str_bytes.rs @@ -104,6 +104,7 @@ impl Buf { self.inner.shrink_to(min_capacity) } + #[inline] pub fn as_slice(&self) -> &Slice { unsafe { mem::transmute(&*self.inner) } } From eca1e8bd9beeaabbc240ad342892f26998ad7f35 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 18:48:15 +0000 Subject: [PATCH 2/7] Inline PathBuf::deref to make it zero cost --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index fbbdc1ddac297..f00ef26930921 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1535,7 +1535,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) } From ea6bb7fe17395545a8f22563ed831ac5d2b4389f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 18:56:30 +0000 Subject: [PATCH 3/7] Inline `AsRef for str` --- src/libstd/path.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index f00ef26930921..7ea642942dd74 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2655,6 +2655,7 @@ impl AsRef for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for str { + #[inline] fn as_ref(&self) -> &Path { Path::new(self) } From bf1d20c4b60c20a780e8d98882e24b0e48b1a33d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 19:02:14 +0000 Subject: [PATCH 4/7] Inline `impl From for PathBuf` --- src/libstd/path.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 7ea642942dd74..a09300ffe956f 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1475,6 +1475,7 @@ impl From 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 } } From cd5ab974808732a7f1b6923a54cf8a75dff1599e Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 19:06:18 +0000 Subject: [PATCH 5/7] inline `impl AsRef for OsString` --- src/libstd/ffi/os_str.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index ec2d07f34ca5f..77da97219b147 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -966,6 +966,7 @@ impl AsRef for OsStr { #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for OsString { + #[inline] fn as_ref(&self) -> &OsStr { self } From 76e698fc56473702ce2db81296b45c5fd267485e Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 19:18:17 +0000 Subject: [PATCH 6/7] inline `impl AsRef for PathBuf` --- src/libstd/path.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index a09300ffe956f..a703cb748e06b 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2671,6 +2671,7 @@ impl AsRef for String { #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for PathBuf { + #[inline] fn as_ref(&self) -> &Path { self } From 5f3f1a3606a5f13177a1634ba80d6386e5132518 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 10 Jan 2020 19:27:02 +0000 Subject: [PATCH 7/7] inline `impl From for Box` --- src/libstd/error.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 1407fe2771553..b480581e21ba9 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -250,6 +250,7 @@ impl From for Box { /// assert!( /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) /// ``` + #[inline] fn from(err: String) -> Box { struct StringError(String); @@ -317,6 +318,7 @@ impl<'a> From<&str> for Box { /// assert!( /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) /// ``` + #[inline] fn from(err: &str) -> Box { From::from(String::from(err)) }