From 5b8bfe047123bad63ead0370c165cd9307a07caa Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Wed, 3 Apr 2019 13:01:01 +0200 Subject: improve worst-case performance of HashSet.is_subset --- src/libstd/collections/hash/set.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 89d5b2ff30f..b9fcc2365fa 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -627,7 +627,11 @@ impl HashSet /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn is_subset(&self, other: &HashSet) -> bool { - self.iter().all(|v| other.contains(v)) + if self.len() <= other.len() { + self.iter().all(|v| other.contains(v)) + } else { + false + } } /// Returns `true` if the set is a superset of another, -- cgit 1.4.1-3-g733a5 From a37c33b9261f534b56434c83258ff24d24bf9351 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Thu, 4 Apr 2019 10:51:18 +0200 Subject: Mark unix::ffi::OsStrExt methods as inline --- src/libstd/ffi/os_str.rs | 1 + src/libstd/sys_common/os_str_bytes.rs | 2 ++ 2 files changed, 3 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 01e7a57cd00..13aee783750 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -960,6 +960,7 @@ impl IntoInner for OsString { } impl AsInner for OsStr { + #[inline] fn as_inner(&self) -> &Slice { &self.inner } diff --git a/src/libstd/sys_common/os_str_bytes.rs b/src/libstd/sys_common/os_str_bytes.rs index 7cc93477a73..a4961974d89 100644 --- a/src/libstd/sys_common/os_str_bytes.rs +++ b/src/libstd/sys_common/os_str_bytes.rs @@ -236,9 +236,11 @@ pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] impl OsStrExt for OsStr { + #[inline] fn from_bytes(slice: &[u8]) -> &OsStr { unsafe { mem::transmute(slice) } } + #[inline] fn as_bytes(&self) -> &[u8] { &self.as_inner().inner } -- cgit 1.4.1-3-g733a5