Skip to content

Commit 556fc40

Browse files
committed
Mark HashSet functions with #[inline]
1 parent a533504 commit 556fc40

File tree

1 file changed

+45
-0
lines changed
  • src/libstd/collections/hash

1 file changed

+45
-0
lines changed

src/libstd/collections/hash/set.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl<T, S> HashSet<T, S> {
181181
/// println!("{}", x);
182182
/// }
183183
/// ```
184+
#[inline]
184185
#[stable(feature = "rust1", since = "1.0.0")]
185186
pub fn iter(&self) -> Iter<'_, T> {
186187
Iter { iter: self.map.keys() }
@@ -198,6 +199,7 @@ impl<T, S> HashSet<T, S> {
198199
/// v.insert(1);
199200
/// assert_eq!(v.len(), 1);
200201
/// ```
202+
#[inline]
201203
#[stable(feature = "rust1", since = "1.0.0")]
202204
pub fn len(&self) -> usize {
203205
self.map.len()
@@ -215,6 +217,7 @@ impl<T, S> HashSet<T, S> {
215217
/// v.insert(1);
216218
/// assert!(!v.is_empty());
217219
/// ```
220+
#[inline]
218221
#[stable(feature = "rust1", since = "1.0.0")]
219222
pub fn is_empty(&self) -> bool {
220223
self.map.is_empty()
@@ -255,6 +258,7 @@ impl<T, S> HashSet<T, S> {
255258
/// v.clear();
256259
/// assert!(v.is_empty());
257260
/// ```
261+
#[inline]
258262
#[stable(feature = "rust1", since = "1.0.0")]
259263
pub fn clear(&mut self) {
260264
self.map.clear()
@@ -332,6 +336,7 @@ impl<T, S> HashSet<T, S>
332336
/// let set: HashSet<i32> = HashSet::with_hasher(hasher);
333337
/// let hasher: &RandomState = set.hasher();
334338
/// ```
339+
#[inline]
335340
#[stable(feature = "hashmap_public_hasher", since = "1.9.0")]
336341
pub fn hasher(&self) -> &S {
337342
self.map.hasher()
@@ -353,6 +358,7 @@ impl<T, S> HashSet<T, S>
353358
/// set.reserve(10);
354359
/// assert!(set.capacity() >= 10);
355360
/// ```
361+
#[inline]
356362
#[stable(feature = "rust1", since = "1.0.0")]
357363
pub fn reserve(&mut self, additional: usize) {
358364
self.map.reserve(additional)
@@ -397,6 +403,7 @@ impl<T, S> HashSet<T, S>
397403
/// set.shrink_to_fit();
398404
/// assert!(set.capacity() >= 2);
399405
/// ```
406+
#[inline]
400407
#[stable(feature = "rust1", since = "1.0.0")]
401408
pub fn shrink_to_fit(&mut self) {
402409
self.map.shrink_to_fit()
@@ -453,6 +460,7 @@ impl<T, S> HashSet<T, S>
453460
/// let diff: HashSet<_> = b.difference(&a).collect();
454461
/// assert_eq!(diff, [4].iter().collect());
455462
/// ```
463+
#[inline]
456464
#[stable(feature = "rust1", since = "1.0.0")]
457465
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> {
458466
Difference {
@@ -482,6 +490,7 @@ impl<T, S> HashSet<T, S>
482490
/// assert_eq!(diff1, diff2);
483491
/// assert_eq!(diff1, [1, 4].iter().collect());
484492
/// ```
493+
#[inline]
485494
#[stable(feature = "rust1", since = "1.0.0")]
486495
pub fn symmetric_difference<'a>(&'a self,
487496
other: &'a HashSet<T, S>)
@@ -507,6 +516,7 @@ impl<T, S> HashSet<T, S>
507516
/// let intersection: HashSet<_> = a.intersection(&b).collect();
508517
/// assert_eq!(intersection, [2, 3].iter().collect());
509518
/// ```
519+
#[inline]
510520
#[stable(feature = "rust1", since = "1.0.0")]
511521
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> {
512522
if self.len() <= other.len() {
@@ -540,6 +550,7 @@ impl<T, S> HashSet<T, S>
540550
/// let union: HashSet<_> = a.union(&b).collect();
541551
/// assert_eq!(union, [1, 2, 3, 4].iter().collect());
542552
/// ```
553+
#[inline]
543554
#[stable(feature = "rust1", since = "1.0.0")]
544555
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
545556
if self.len() <= other.len() {
@@ -571,6 +582,7 @@ impl<T, S> HashSet<T, S>
571582
///
572583
/// [`Eq`]: ../../std/cmp/trait.Eq.html
573584
/// [`Hash`]: ../../std/hash/trait.Hash.html
585+
#[inline]
574586
#[stable(feature = "rust1", since = "1.0.0")]
575587
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
576588
where T: Borrow<Q>,
@@ -597,6 +609,7 @@ impl<T, S> HashSet<T, S>
597609
///
598610
/// [`Eq`]: ../../std/cmp/trait.Eq.html
599611
/// [`Hash`]: ../../std/hash/trait.Hash.html
612+
#[inline]
600613
#[stable(feature = "set_recovery", since = "1.9.0")]
601614
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
602615
where T: Borrow<Q>,
@@ -700,6 +713,7 @@ impl<T, S> HashSet<T, S>
700713
/// assert_eq!(set.insert(2), false);
701714
/// assert_eq!(set.len(), 1);
702715
/// ```
716+
#[inline]
703717
#[stable(feature = "rust1", since = "1.0.0")]
704718
pub fn insert(&mut self, value: T) -> bool {
705719
self.map.insert(value, ()).is_none()
@@ -720,6 +734,7 @@ impl<T, S> HashSet<T, S>
720734
/// set.replace(Vec::with_capacity(10));
721735
/// assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
722736
/// ```
737+
#[inline]
723738
#[stable(feature = "set_recovery", since = "1.9.0")]
724739
pub fn replace(&mut self, value: T) -> Option<T> {
725740
match self.map.entry(value) {
@@ -752,6 +767,7 @@ impl<T, S> HashSet<T, S>
752767
///
753768
/// [`Eq`]: ../../std/cmp/trait.Eq.html
754769
/// [`Hash`]: ../../std/hash/trait.Hash.html
770+
#[inline]
755771
#[stable(feature = "rust1", since = "1.0.0")]
756772
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
757773
where T: Borrow<Q>,
@@ -778,6 +794,7 @@ impl<T, S> HashSet<T, S>
778794
///
779795
/// [`Eq`]: ../../std/cmp/trait.Eq.html
780796
/// [`Hash`]: ../../std/hash/trait.Hash.html
797+
#[inline]
781798
#[stable(feature = "set_recovery", since = "1.9.0")]
782799
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
783800
where T: Borrow<Q>,
@@ -844,6 +861,7 @@ impl<T, S> FromIterator<T> for HashSet<T, S>
844861
where T: Eq + Hash,
845862
S: BuildHasher + Default
846863
{
864+
#[inline]
847865
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> HashSet<T, S> {
848866
let mut set = HashSet::with_hasher(Default::default());
849867
set.extend(iter);
@@ -856,6 +874,7 @@ impl<T, S> Extend<T> for HashSet<T, S>
856874
where T: Eq + Hash,
857875
S: BuildHasher
858876
{
877+
#[inline]
859878
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
860879
self.map.extend(iter.into_iter().map(|k| (k, ())));
861880
}
@@ -866,6 +885,7 @@ impl<'a, T, S> Extend<&'a T> for HashSet<T, S>
866885
where T: 'a + Eq + Hash + Copy,
867886
S: BuildHasher
868887
{
888+
#[inline]
869889
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
870890
self.extend(iter.into_iter().cloned());
871891
}
@@ -877,6 +897,7 @@ impl<T, S> Default for HashSet<T, S>
877897
S: BuildHasher + Default
878898
{
879899
/// Creates an empty `HashSet<T, S>` with the `Default` value for the hasher.
900+
#[inline]
880901
fn default() -> HashSet<T, S> {
881902
HashSet { map: HashMap::default() }
882903
}
@@ -1105,6 +1126,7 @@ impl<'a, T, S> IntoIterator for &'a HashSet<T, S> {
11051126
type Item = &'a T;
11061127
type IntoIter = Iter<'a, T>;
11071128

1129+
#[inline]
11081130
fn into_iter(self) -> Iter<'a, T> {
11091131
self.iter()
11101132
}
@@ -1135,13 +1157,15 @@ impl<T, S> IntoIterator for HashSet<T, S> {
11351157
/// println!("{}", x);
11361158
/// }
11371159
/// ```
1160+
#[inline]
11381161
fn into_iter(self) -> IntoIter<T> {
11391162
IntoIter { iter: self.map.into_iter() }
11401163
}
11411164
}
11421165

11431166
#[stable(feature = "rust1", since = "1.0.0")]
11441167
impl<K> Clone for Iter<'_, K> {
1168+
#[inline]
11451169
fn clone(&self) -> Self {
11461170
Iter { iter: self.iter.clone() }
11471171
}
@@ -1150,15 +1174,18 @@ impl<K> Clone for Iter<'_, K> {
11501174
impl<'a, K> Iterator for Iter<'a, K> {
11511175
type Item = &'a K;
11521176

1177+
#[inline]
11531178
fn next(&mut self) -> Option<&'a K> {
11541179
self.iter.next()
11551180
}
1181+
#[inline]
11561182
fn size_hint(&self) -> (usize, Option<usize>) {
11571183
self.iter.size_hint()
11581184
}
11591185
}
11601186
#[stable(feature = "rust1", since = "1.0.0")]
11611187
impl<K> ExactSizeIterator for Iter<'_, K> {
1188+
#[inline]
11621189
fn len(&self) -> usize {
11631190
self.iter.len()
11641191
}
@@ -1177,15 +1204,18 @@ impl<K: fmt::Debug> fmt::Debug for Iter<'_, K> {
11771204
impl<K> Iterator for IntoIter<K> {
11781205
type Item = K;
11791206

1207+
#[inline]
11801208
fn next(&mut self) -> Option<K> {
11811209
self.iter.next().map(|(k, _)| k)
11821210
}
1211+
#[inline]
11831212
fn size_hint(&self) -> (usize, Option<usize>) {
11841213
self.iter.size_hint()
11851214
}
11861215
}
11871216
#[stable(feature = "rust1", since = "1.0.0")]
11881217
impl<K> ExactSizeIterator for IntoIter<K> {
1218+
#[inline]
11891219
fn len(&self) -> usize {
11901220
self.iter.len()
11911221
}
@@ -1208,15 +1238,18 @@ impl<K: fmt::Debug> fmt::Debug for IntoIter<K> {
12081238
impl<'a, K> Iterator for Drain<'a, K> {
12091239
type Item = K;
12101240

1241+
#[inline]
12111242
fn next(&mut self) -> Option<K> {
12121243
self.iter.next().map(|(k, _)| k)
12131244
}
1245+
#[inline]
12141246
fn size_hint(&self) -> (usize, Option<usize>) {
12151247
self.iter.size_hint()
12161248
}
12171249
}
12181250
#[stable(feature = "rust1", since = "1.0.0")]
12191251
impl<K> ExactSizeIterator for Drain<'_, K> {
1252+
#[inline]
12201253
fn len(&self) -> usize {
12211254
self.iter.len()
12221255
}
@@ -1237,6 +1270,7 @@ impl<K: fmt::Debug> fmt::Debug for Drain<'_, K> {
12371270

12381271
#[stable(feature = "rust1", since = "1.0.0")]
12391272
impl<T, S> Clone for Intersection<'_, T, S> {
1273+
#[inline]
12401274
fn clone(&self) -> Self {
12411275
Intersection { iter: self.iter.clone(), ..*self }
12421276
}
@@ -1249,6 +1283,7 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S>
12491283
{
12501284
type Item = &'a T;
12511285

1286+
#[inline]
12521287
fn next(&mut self) -> Option<&'a T> {
12531288
loop {
12541289
let elt = self.iter.next()?;
@@ -1258,6 +1293,7 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S>
12581293
}
12591294
}
12601295

1296+
#[inline]
12611297
fn size_hint(&self) -> (usize, Option<usize>) {
12621298
let (_, upper) = self.iter.size_hint();
12631299
(0, upper)
@@ -1283,6 +1319,7 @@ impl<T, S> FusedIterator for Intersection<'_, T, S>
12831319

12841320
#[stable(feature = "rust1", since = "1.0.0")]
12851321
impl<T, S> Clone for Difference<'_, T, S> {
1322+
#[inline]
12861323
fn clone(&self) -> Self {
12871324
Difference { iter: self.iter.clone(), ..*self }
12881325
}
@@ -1295,6 +1332,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S>
12951332
{
12961333
type Item = &'a T;
12971334

1335+
#[inline]
12981336
fn next(&mut self) -> Option<&'a T> {
12991337
loop {
13001338
let elt = self.iter.next()?;
@@ -1304,6 +1342,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S>
13041342
}
13051343
}
13061344

1345+
#[inline]
13071346
fn size_hint(&self) -> (usize, Option<usize>) {
13081347
let (_, upper) = self.iter.size_hint();
13091348
(0, upper)
@@ -1329,6 +1368,7 @@ impl<T, S> fmt::Debug for Difference<'_, T, S>
13291368

13301369
#[stable(feature = "rust1", since = "1.0.0")]
13311370
impl<T, S> Clone for SymmetricDifference<'_, T, S> {
1371+
#[inline]
13321372
fn clone(&self) -> Self {
13331373
SymmetricDifference { iter: self.iter.clone() }
13341374
}
@@ -1341,9 +1381,11 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S>
13411381
{
13421382
type Item = &'a T;
13431383

1384+
#[inline]
13441385
fn next(&mut self) -> Option<&'a T> {
13451386
self.iter.next()
13461387
}
1388+
#[inline]
13471389
fn size_hint(&self) -> (usize, Option<usize>) {
13481390
self.iter.size_hint()
13491391
}
@@ -1368,6 +1410,7 @@ impl<T, S> fmt::Debug for SymmetricDifference<'_, T, S>
13681410

13691411
#[stable(feature = "rust1", since = "1.0.0")]
13701412
impl<T, S> Clone for Union<'_, T, S> {
1413+
#[inline]
13711414
fn clone(&self) -> Self {
13721415
Union { iter: self.iter.clone() }
13731416
}
@@ -1397,9 +1440,11 @@ impl<'a, T, S> Iterator for Union<'a, T, S>
13971440
{
13981441
type Item = &'a T;
13991442

1443+
#[inline]
14001444
fn next(&mut self) -> Option<&'a T> {
14011445
self.iter.next()
14021446
}
1447+
#[inline]
14031448
fn size_hint(&self) -> (usize, Option<usize>) {
14041449
self.iter.size_hint()
14051450
}

0 commit comments

Comments
 (0)