@@ -4,7 +4,7 @@ use std::borrow::Borrow;
4
4
use std:: collections:: hash_map:: RandomState ;
5
5
use std:: fmt;
6
6
use std:: future:: Future ;
7
- use std:: hash:: { BuildHasher , Hash , Hasher } ;
7
+ use std:: hash:: { BuildHasher , Hash } ;
8
8
use std:: marker:: PhantomData ;
9
9
use tokio:: runtime:: Handle ;
10
10
use tokio:: task:: { AbortHandle , Id , JoinError , JoinSet , LocalSet } ;
@@ -391,13 +391,13 @@ where
391
391
392
392
fn insert ( & mut self , mut key : K , mut abort : AbortHandle ) {
393
393
let hash_builder = self . hashes_by_task . hasher ( ) ;
394
- let hash = hash_one ( hash_builder , & key) ;
394
+ let hash = hash_builder . hash_one ( & key) ;
395
395
let id = abort. id ( ) ;
396
396
397
397
// Insert the new key into the map of tasks by keys.
398
398
let entry =
399
399
self . tasks_by_key
400
- . entry ( hash, |( k, _) | * k == key, |( k, _) | hash_one ( hash_builder , k) ) ;
400
+ . entry ( hash, |( k, _) | * k == key, |( k, _) | hash_builder . hash_one ( k) ) ;
401
401
match entry {
402
402
Entry :: Occupied ( occ) => {
403
403
// There was a previous task spawned with the same key! Cancel
@@ -673,9 +673,9 @@ where
673
673
/// ```
674
674
#[ inline]
675
675
pub fn reserve ( & mut self , additional : usize ) {
676
- let hash_builder = self . hashes_by_task . hasher ( ) ;
677
- self . tasks_by_key
678
- . reserve ( additional , | ( k , _ ) | hash_one ( hash_builder , k ) ) ;
676
+ self . tasks_by_key . reserve ( additional , | ( k , _ ) | {
677
+ self . hashes_by_task . hasher ( ) . hash_one ( k )
678
+ } ) ;
679
679
self . hashes_by_task . reserve ( additional) ;
680
680
}
681
681
@@ -701,9 +701,8 @@ where
701
701
#[ inline]
702
702
pub fn shrink_to_fit ( & mut self ) {
703
703
self . hashes_by_task . shrink_to_fit ( ) ;
704
- let hash_builder = self . hashes_by_task . hasher ( ) ;
705
704
self . tasks_by_key
706
- . shrink_to_fit ( |( k, _) | hash_one ( hash_builder , k) ) ;
705
+ . shrink_to_fit ( |( k, _) | self . hashes_by_task . hasher ( ) . hash_one ( k) ) ;
707
706
}
708
707
709
708
/// Shrinks the capacity of the map with a lower limit. It will drop
@@ -732,9 +731,9 @@ where
732
731
#[ inline]
733
732
pub fn shrink_to ( & mut self , min_capacity : usize ) {
734
733
self . hashes_by_task . shrink_to ( min_capacity) ;
735
- let hash_builder = self . hashes_by_task . hasher ( ) ;
736
- self . tasks_by_key
737
- . shrink_to ( min_capacity , | ( k , _ ) | hash_one ( hash_builder , k ) )
734
+ self . tasks_by_key . shrink_to ( min_capacity , | ( k , _ ) | {
735
+ self . hashes_by_task . hasher ( ) . hash_one ( k )
736
+ } )
738
737
}
739
738
740
739
/// Look up a task in the map by its key, returning the key and abort handle.
@@ -743,8 +742,7 @@ where
743
742
Q : ?Sized + Hash + Eq ,
744
743
K : Borrow < Q > ,
745
744
{
746
- let hash_builder = self . hashes_by_task . hasher ( ) ;
747
- let hash = hash_one ( hash_builder, key) ;
745
+ let hash = self . hashes_by_task . hasher ( ) . hash_one ( key) ;
748
746
self . tasks_by_key . find ( hash, |( k, _) | k. borrow ( ) == key)
749
747
}
750
748
@@ -765,18 +763,6 @@ where
765
763
}
766
764
}
767
765
768
- /// Returns the hash for a given key.
769
- #[ inline]
770
- fn hash_one < S , Q > ( hash_builder : & S , key : & Q ) -> u64
771
- where
772
- Q : ?Sized + Hash ,
773
- S : BuildHasher ,
774
- {
775
- let mut hasher = hash_builder. build_hasher ( ) ;
776
- key. hash ( & mut hasher) ;
777
- hasher. finish ( )
778
- }
779
-
780
766
impl < K , V , S > JoinMap < K , V , S >
781
767
where
782
768
V : ' static ,
0 commit comments