@@ -213,6 +213,22 @@ pub(crate) fn make_hasher<K: Hash, V>(
213213 move |val| make_hash ( hash_builder, & val. 0 )
214214}
215215
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+
216232#[ cfg_attr( feature = "inline-more" , inline) ]
217233pub ( crate ) fn make_hash < K : Hash + ?Sized > ( hash_builder : & impl BuildHasher , val : & K ) -> u64 {
218234 let mut state = hash_builder. build_hasher ( ) ;
@@ -771,7 +787,7 @@ where
771787 #[ cfg_attr( feature = "inline-more" , inline) ]
772788 pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V , S > {
773789 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) ) {
775791 Entry :: Occupied ( OccupiedEntry {
776792 hash,
777793 key : Some ( key) ,
@@ -858,7 +874,7 @@ where
858874 Q : Hash + Eq ,
859875 {
860876 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 ) )
862878 }
863879
864880 /// Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.
@@ -966,7 +982,7 @@ where
966982 Q : Hash + Eq ,
967983 {
968984 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 ) )
970986 }
971987
972988 /// Inserts a key-value pair into the map.
@@ -997,7 +1013,7 @@ where
9971013 #[ cfg_attr( feature = "inline-more" , inline) ]
9981014 pub fn insert ( & mut self , k : K , v : V ) -> Option < V > {
9991015 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 ) ) {
10011017 Some ( mem:: replace ( item, v) )
10021018 } else {
10031019 let hash_builder = & self . hash_builder ;
@@ -1066,7 +1082,7 @@ where
10661082 Q : Hash + Eq ,
10671083 {
10681084 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 ) )
10701086 }
10711087}
10721088
@@ -1533,7 +1549,7 @@ impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
15331549 K : Borrow < Q > ,
15341550 Q : Eq ,
15351551 {
1536- self . from_hash ( hash, |q| q . borrow ( ) . eq ( k) )
1552+ self . from_hash ( hash, equivalent_single ( k) )
15371553 }
15381554}
15391555
@@ -1590,7 +1606,7 @@ impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
15901606 K : Borrow < Q > ,
15911607 Q : Eq ,
15921608 {
1593- self . from_hash ( hash, |q| q . borrow ( ) . eq ( k) )
1609+ self . from_hash ( hash, equivalent_single ( k) )
15941610 }
15951611
15961612 #[ cfg_attr( feature = "inline-more" , inline) ]
0 commit comments