@@ -213,6 +213,22 @@ pub(crate) fn make_hasher<K: Hash, V>(
213
213
move |val| make_hash ( hash_builder, & val. 0 )
214
214
}
215
215
216
+ fn equivalent < Q , K , V > ( k : & Q ) -> impl Fn ( & ( K , V ) ) -> bool + ' _
217
+ where
218
+ K : Borrow < Q > ,
219
+ Q : ?Sized + Eq ,
220
+ {
221
+ move |x| k. eq ( x. 0 . borrow ( ) )
222
+ }
223
+
224
+ fn equivalent_single < Q , K > ( k : & Q ) -> impl Fn ( & K ) -> bool + ' _
225
+ where
226
+ K : Borrow < Q > ,
227
+ Q : ?Sized + Eq ,
228
+ {
229
+ move |x| k. eq ( x. borrow ( ) )
230
+ }
231
+
216
232
#[ cfg_attr( feature = "inline-more" , inline) ]
217
233
pub ( crate ) fn make_hash < K : Hash + ?Sized > ( hash_builder : & impl BuildHasher , val : & K ) -> u64 {
218
234
let mut state = hash_builder. build_hasher ( ) ;
@@ -771,7 +787,7 @@ where
771
787
#[ cfg_attr( feature = "inline-more" , inline) ]
772
788
pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V , S > {
773
789
let hash = make_hash ( & self . hash_builder , & key) ;
774
- if let Some ( elem) = self . table . find ( hash, |q| q . 0 . eq ( & key) ) {
790
+ if let Some ( elem) = self . table . find ( hash, equivalent ( & key) ) {
775
791
Entry :: Occupied ( OccupiedEntry {
776
792
hash,
777
793
key : Some ( key) ,
@@ -858,7 +874,7 @@ where
858
874
Q : Hash + Eq ,
859
875
{
860
876
let hash = make_hash ( & self . hash_builder , k) ;
861
- self . table . get ( hash, |x| k . eq ( x . 0 . borrow ( ) ) )
877
+ self . table . get ( hash, equivalent ( k ) )
862
878
}
863
879
864
880
/// Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.
@@ -966,7 +982,7 @@ where
966
982
Q : Hash + Eq ,
967
983
{
968
984
let hash = make_hash ( & self . hash_builder , k) ;
969
- self . table . get_mut ( hash, |x| k . eq ( x . 0 . borrow ( ) ) )
985
+ self . table . get_mut ( hash, equivalent ( k ) )
970
986
}
971
987
972
988
/// Inserts a key-value pair into the map.
@@ -997,7 +1013,7 @@ where
997
1013
#[ cfg_attr( feature = "inline-more" , inline) ]
998
1014
pub fn insert ( & mut self , k : K , v : V ) -> Option < V > {
999
1015
let hash = make_hash ( & self . hash_builder , & k) ;
1000
- if let Some ( ( _, item) ) = self . table . get_mut ( hash, |x| k . eq ( & x . 0 ) ) {
1016
+ if let Some ( ( _, item) ) = self . table . get_mut ( hash, equivalent ( & k ) ) {
1001
1017
Some ( mem:: replace ( item, v) )
1002
1018
} else {
1003
1019
let hash_builder = & self . hash_builder ;
@@ -1066,7 +1082,7 @@ where
1066
1082
Q : Hash + Eq ,
1067
1083
{
1068
1084
let hash = make_hash ( & self . hash_builder , & k) ;
1069
- self . table . remove_entry ( hash, |x| k . eq ( x . 0 . borrow ( ) ) )
1085
+ self . table . remove_entry ( hash, equivalent ( k ) )
1070
1086
}
1071
1087
}
1072
1088
@@ -1533,7 +1549,7 @@ impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
1533
1549
K : Borrow < Q > ,
1534
1550
Q : Eq ,
1535
1551
{
1536
- self . from_hash ( hash, |q| q . borrow ( ) . eq ( k) )
1552
+ self . from_hash ( hash, equivalent_single ( k) )
1537
1553
}
1538
1554
}
1539
1555
@@ -1590,7 +1606,7 @@ impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
1590
1606
K : Borrow < Q > ,
1591
1607
Q : Eq ,
1592
1608
{
1593
- self . from_hash ( hash, |q| q . borrow ( ) . eq ( k) )
1609
+ self . from_hash ( hash, equivalent_single ( k) )
1594
1610
}
1595
1611
1596
1612
#[ cfg_attr( feature = "inline-more" , inline) ]
0 commit comments