@@ -206,13 +206,18 @@ impl<K: Clone, V: Clone, S: Clone> Clone for HashMap<K, V, S> {
206
206
}
207
207
}
208
208
209
+ /// Ensures that a single closure type across uses of this which, in turn prevents multiple
210
+ /// instances of any functions like RawTable::reserve from being generated
209
211
#[ cfg_attr( feature = "inline-more" , inline) ]
210
212
pub ( crate ) fn make_hasher < K : Hash , V > (
211
213
hash_builder : & impl BuildHasher ,
212
214
) -> impl Fn ( & ( K , V ) ) -> u64 + ' _ {
213
215
move |val| make_hash ( hash_builder, & val. 0 )
214
216
}
215
217
218
+ /// Ensures that a single closure type across uses of this which, in turn prevents multiple
219
+ /// instances of any functions like RawTable::reserve from being generated
220
+ #[ cfg_attr( feature = "inline-more" , inline) ]
216
221
fn equivalent < Q , K , V > ( k : & Q ) -> impl Fn ( & ( K , V ) ) -> bool + ' _
217
222
where
218
223
K : Borrow < Q > ,
@@ -221,6 +226,9 @@ where
221
226
move |x| k. eq ( x. 0 . borrow ( ) )
222
227
}
223
228
229
+ /// Ensures that a single closure type across uses of this which, in turn prevents multiple
230
+ /// instances of any functions like RawTable::reserve from being generated
231
+ #[ cfg_attr( feature = "inline-more" , inline) ]
224
232
fn equivalent_single < Q , K > ( k : & Q ) -> impl Fn ( & K ) -> bool + ' _
225
233
where
226
234
K : Borrow < Q > ,
@@ -686,8 +694,8 @@ where
686
694
/// ```
687
695
#[ cfg_attr( feature = "inline-more" , inline) ]
688
696
pub fn reserve ( & mut self , additional : usize ) {
689
- let hash_builder = & self . hash_builder ;
690
- self . table . reserve ( additional, make_hasher ( hash_builder) ) ;
697
+ self . table
698
+ . reserve ( additional, make_hasher ( & self . hash_builder ) ) ;
691
699
}
692
700
693
701
/// Tries to reserve capacity for at least `additional` more elements to be inserted
@@ -708,9 +716,8 @@ where
708
716
/// ```
709
717
#[ cfg_attr( feature = "inline-more" , inline) ]
710
718
pub fn try_reserve ( & mut self , additional : usize ) -> Result < ( ) , TryReserveError > {
711
- let hash_builder = & self . hash_builder ;
712
719
self . table
713
- . try_reserve ( additional, make_hasher ( hash_builder) )
720
+ . try_reserve ( additional, make_hasher ( & self . hash_builder ) )
714
721
}
715
722
716
723
/// Shrinks the capacity of the map as much as possible. It will drop
@@ -731,8 +738,7 @@ where
731
738
/// ```
732
739
#[ cfg_attr( feature = "inline-more" , inline) ]
733
740
pub fn shrink_to_fit ( & mut self ) {
734
- let hash_builder = & self . hash_builder ;
735
- self . table . shrink_to ( 0 , make_hasher ( hash_builder) ) ;
741
+ self . table . shrink_to ( 0 , make_hasher ( & self . hash_builder ) ) ;
736
742
}
737
743
738
744
/// Shrinks the capacity of the map with a lower limit. It will drop
@@ -760,9 +766,8 @@ where
760
766
/// ```
761
767
#[ cfg_attr( feature = "inline-more" , inline) ]
762
768
pub fn shrink_to ( & mut self , min_capacity : usize ) {
763
- let hash_builder = & self . hash_builder ;
764
769
self . table
765
- . shrink_to ( min_capacity, make_hasher ( hash_builder) ) ;
770
+ . shrink_to ( min_capacity, make_hasher ( & self . hash_builder ) ) ;
766
771
}
767
772
768
773
/// Gets the given key's corresponding entry in the map for in-place manipulation.
@@ -1016,8 +1021,8 @@ where
1016
1021
if let Some ( ( _, item) ) = self . table . get_mut ( hash, equivalent ( & k) ) {
1017
1022
Some ( mem:: replace ( item, v) )
1018
1023
} else {
1019
- let hash_builder = & self . hash_builder ;
1020
- self . table . insert ( hash, ( k, v) , make_hasher ( hash_builder) ) ;
1024
+ self . table
1025
+ . insert ( hash, ( k, v) , make_hasher ( & self . hash_builder ) ) ;
1021
1026
None
1022
1027
}
1023
1028
}
@@ -1966,10 +1971,9 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
1966
1971
K : Hash ,
1967
1972
S : BuildHasher ,
1968
1973
{
1969
- let hash_builder = self . hash_builder ;
1970
1974
let & mut ( ref mut k, ref mut v) =
1971
1975
self . table
1972
- . insert_entry ( hash, ( key, value) , make_hasher ( hash_builder) ) ;
1976
+ . insert_entry ( hash, ( key, value) , make_hasher ( self . hash_builder ) ) ;
1973
1977
( k, v)
1974
1978
}
1975
1979
@@ -1998,7 +2002,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
1998
2002
S : BuildHasher ,
1999
2003
{
2000
2004
let hash_builder = self . hash_builder ;
2001
- let mut hasher = self . hash_builder . build_hasher ( ) ;
2005
+ let mut hasher = hash_builder. build_hasher ( ) ;
2002
2006
key. hash ( & mut hasher) ;
2003
2007
2004
2008
let elem = self
@@ -2007,7 +2011,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
2007
2011
RawOccupiedEntryMut {
2008
2012
elem,
2009
2013
table : self . table ,
2010
- hash_builder : self . hash_builder ,
2014
+ hash_builder,
2011
2015
}
2012
2016
}
2013
2017
}
@@ -2996,9 +3000,12 @@ impl<'a, K, V, S> VacantEntry<'a, K, V, S> {
2996
3000
K : Hash ,
2997
3001
S : BuildHasher ,
2998
3002
{
2999
- let hash_builder = & self . table . hash_builder ;
3000
3003
let table = & mut self . table . table ;
3001
- let entry = table. insert_entry ( self . hash , ( self . key , value) , make_hasher ( hash_builder) ) ;
3004
+ let entry = table. insert_entry (
3005
+ self . hash ,
3006
+ ( self . key , value) ,
3007
+ make_hasher ( & self . table . hash_builder ) ,
3008
+ ) ;
3002
3009
& mut entry. 1
3003
3010
}
3004
3011
@@ -3008,11 +3015,11 @@ impl<'a, K, V, S> VacantEntry<'a, K, V, S> {
3008
3015
K : Hash ,
3009
3016
S : BuildHasher ,
3010
3017
{
3011
- let hash_builder = & self . table . hash_builder ;
3012
- let elem = self
3013
- . table
3014
- . table
3015
- . insert ( self . hash , ( self . key , value ) , make_hasher ( hash_builder ) ) ;
3018
+ let elem = self . table . table . insert (
3019
+ self . hash ,
3020
+ ( self . key , value ) ,
3021
+ make_hasher ( & self . table . hash_builder ) ,
3022
+ ) ;
3016
3023
OccupiedEntry {
3017
3024
hash : self . hash ,
3018
3025
key : None ,
0 commit comments