diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index f8a93b680f76..b610e09ae749 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -181,6 +181,7 @@ impl HashSet { /// println!("{}", x); /// } /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn iter(&self) -> Iter<'_, T> { Iter { iter: self.map.keys() } @@ -198,6 +199,7 @@ impl HashSet { /// v.insert(1); /// assert_eq!(v.len(), 1); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.map.len() @@ -215,6 +217,7 @@ impl HashSet { /// v.insert(1); /// assert!(!v.is_empty()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_empty(&self) -> bool { self.map.is_empty() @@ -255,6 +258,7 @@ impl HashSet { /// v.clear(); /// assert!(v.is_empty()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn clear(&mut self) { self.map.clear() @@ -332,6 +336,7 @@ impl HashSet /// let set: HashSet = HashSet::with_hasher(hasher); /// let hasher: &RandomState = set.hasher(); /// ``` + #[inline] #[stable(feature = "hashmap_public_hasher", since = "1.9.0")] pub fn hasher(&self) -> &S { self.map.hasher() @@ -353,6 +358,7 @@ impl HashSet /// set.reserve(10); /// assert!(set.capacity() >= 10); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn reserve(&mut self, additional: usize) { self.map.reserve(additional) @@ -397,6 +403,7 @@ impl HashSet /// set.shrink_to_fit(); /// assert!(set.capacity() >= 2); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn shrink_to_fit(&mut self) { self.map.shrink_to_fit() @@ -453,6 +460,7 @@ impl HashSet /// let diff: HashSet<_> = b.difference(&a).collect(); /// assert_eq!(diff, [4].iter().collect()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn difference<'a>(&'a self, other: &'a HashSet) -> Difference<'a, T, S> { Difference { @@ -482,6 +490,7 @@ impl HashSet /// assert_eq!(diff1, diff2); /// assert_eq!(diff1, [1, 4].iter().collect()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet) @@ -507,6 +516,7 @@ impl HashSet /// let intersection: HashSet<_> = a.intersection(&b).collect(); /// assert_eq!(intersection, [2, 3].iter().collect()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn intersection<'a>(&'a self, other: &'a HashSet) -> Intersection<'a, T, S> { if self.len() <= other.len() { @@ -540,6 +550,7 @@ impl HashSet /// let union: HashSet<_> = a.union(&b).collect(); /// assert_eq!(union, [1, 2, 3, 4].iter().collect()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn union<'a>(&'a self, other: &'a HashSet) -> Union<'a, T, S> { if self.len() <= other.len() { @@ -571,6 +582,7 @@ impl HashSet /// /// [`Eq`]: ../../std/cmp/trait.Eq.html /// [`Hash`]: ../../std/hash/trait.Hash.html + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn contains(&self, value: &Q) -> bool where T: Borrow, @@ -597,6 +609,7 @@ impl HashSet /// /// [`Eq`]: ../../std/cmp/trait.Eq.html /// [`Hash`]: ../../std/hash/trait.Hash.html + #[inline] #[stable(feature = "set_recovery", since = "1.9.0")] pub fn get(&self, value: &Q) -> Option<&T> where T: Borrow, @@ -700,6 +713,7 @@ impl HashSet /// assert_eq!(set.insert(2), false); /// assert_eq!(set.len(), 1); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()).is_none() @@ -720,6 +734,7 @@ impl HashSet /// set.replace(Vec::with_capacity(10)); /// assert_eq!(set.get(&[][..]).unwrap().capacity(), 10); /// ``` + #[inline] #[stable(feature = "set_recovery", since = "1.9.0")] pub fn replace(&mut self, value: T) -> Option { match self.map.entry(value) { @@ -752,6 +767,7 @@ impl HashSet /// /// [`Eq`]: ../../std/cmp/trait.Eq.html /// [`Hash`]: ../../std/hash/trait.Hash.html + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn remove(&mut self, value: &Q) -> bool where T: Borrow, @@ -778,6 +794,7 @@ impl HashSet /// /// [`Eq`]: ../../std/cmp/trait.Eq.html /// [`Hash`]: ../../std/hash/trait.Hash.html + #[inline] #[stable(feature = "set_recovery", since = "1.9.0")] pub fn take(&mut self, value: &Q) -> Option where T: Borrow, @@ -844,6 +861,7 @@ impl FromIterator for HashSet where T: Eq + Hash, S: BuildHasher + Default { + #[inline] fn from_iter>(iter: I) -> HashSet { let mut set = HashSet::with_hasher(Default::default()); set.extend(iter); @@ -856,6 +874,7 @@ impl Extend for HashSet where T: Eq + Hash, S: BuildHasher { + #[inline] fn extend>(&mut self, iter: I) { self.map.extend(iter.into_iter().map(|k| (k, ()))); } @@ -866,6 +885,7 @@ impl<'a, T, S> Extend<&'a T> for HashSet where T: 'a + Eq + Hash + Copy, S: BuildHasher { + #[inline] fn extend>(&mut self, iter: I) { self.extend(iter.into_iter().cloned()); } @@ -877,6 +897,7 @@ impl Default for HashSet S: BuildHasher + Default { /// Creates an empty `HashSet` with the `Default` value for the hasher. + #[inline] fn default() -> HashSet { HashSet { map: HashMap::default() } } @@ -1105,6 +1126,7 @@ impl<'a, T, S> IntoIterator for &'a HashSet { type Item = &'a T; type IntoIter = Iter<'a, T>; + #[inline] fn into_iter(self) -> Iter<'a, T> { self.iter() } @@ -1135,6 +1157,7 @@ impl IntoIterator for HashSet { /// println!("{}", x); /// } /// ``` + #[inline] fn into_iter(self) -> IntoIter { IntoIter { iter: self.map.into_iter() } } @@ -1142,6 +1165,7 @@ impl IntoIterator for HashSet { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Iter<'_, K> { + #[inline] fn clone(&self) -> Self { Iter { iter: self.iter.clone() } } @@ -1150,15 +1174,18 @@ impl Clone for Iter<'_, K> { impl<'a, K> Iterator for Iter<'a, K> { type Item = &'a K; + #[inline] fn next(&mut self) -> Option<&'a K> { self.iter.next() } + #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Iter<'_, K> { + #[inline] fn len(&self) -> usize { self.iter.len() } @@ -1177,15 +1204,18 @@ impl fmt::Debug for Iter<'_, K> { impl Iterator for IntoIter { type Item = K; + #[inline] fn next(&mut self) -> Option { self.iter.next().map(|(k, _)| k) } + #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter { + #[inline] fn len(&self) -> usize { self.iter.len() } @@ -1208,15 +1238,18 @@ impl fmt::Debug for IntoIter { impl<'a, K> Iterator for Drain<'a, K> { type Item = K; + #[inline] fn next(&mut self) -> Option { self.iter.next().map(|(k, _)| k) } + #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Drain<'_, K> { + #[inline] fn len(&self) -> usize { self.iter.len() } @@ -1237,6 +1270,7 @@ impl fmt::Debug for Drain<'_, K> { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Intersection<'_, T, S> { + #[inline] fn clone(&self) -> Self { Intersection { iter: self.iter.clone(), ..*self } } @@ -1249,6 +1283,7 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S> { type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { loop { let elt = self.iter.next()?; @@ -1258,6 +1293,7 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S> } } + #[inline] fn size_hint(&self) -> (usize, Option) { let (_, upper) = self.iter.size_hint(); (0, upper) @@ -1283,6 +1319,7 @@ impl FusedIterator for Intersection<'_, T, S> #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Difference<'_, T, S> { + #[inline] fn clone(&self) -> Self { Difference { iter: self.iter.clone(), ..*self } } @@ -1295,6 +1332,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S> { type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { loop { let elt = self.iter.next()?; @@ -1304,6 +1342,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S> } } + #[inline] fn size_hint(&self) -> (usize, Option) { let (_, upper) = self.iter.size_hint(); (0, upper) @@ -1329,6 +1368,7 @@ impl fmt::Debug for Difference<'_, T, S> #[stable(feature = "rust1", since = "1.0.0")] impl Clone for SymmetricDifference<'_, T, S> { + #[inline] fn clone(&self) -> Self { SymmetricDifference { iter: self.iter.clone() } } @@ -1341,9 +1381,11 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> { type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { self.iter.next() } + #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } @@ -1368,6 +1410,7 @@ impl fmt::Debug for SymmetricDifference<'_, T, S> #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Union<'_, T, S> { + #[inline] fn clone(&self) -> Self { Union { iter: self.iter.clone() } } @@ -1397,9 +1440,11 @@ impl<'a, T, S> Iterator for Union<'a, T, S> { type Item = &'a T; + #[inline] fn next(&mut self) -> Option<&'a T> { self.iter.next() } + #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() }