@@ -1963,33 +1963,8 @@ impl RandomState {
1963
1963
#[ allow( deprecated) ] // rand
1964
1964
#[ stable( feature = "hashmap_build_hasher" , since = "1.7.0" ) ]
1965
1965
pub fn new ( ) -> RandomState {
1966
- // Historically this function did not cache keys from the OS and instead
1967
- // simply always called `rand::thread_rng().gen()` twice. In #31356 it
1968
- // was discovered, however, that because we re-seed the thread-local RNG
1969
- // from the OS periodically that this can cause excessive slowdown when
1970
- // many hash maps are created on a thread. To solve this performance
1971
- // trap we cache the first set of randomly generated keys per-thread.
1972
- //
1973
- // In doing this, however, we lose the property that all hash maps have
1974
- // nondeterministic iteration order as all of those created on the same
1975
- // thread would have the same hash keys. This property has been nice in
1976
- // the past as it allows for maximal flexibility in the implementation
1977
- // of `HashMap` itself.
1978
- //
1979
- // The constraint here (if there even is one) is just that maps created
1980
- // on the same thread have the same iteration order, and that *may* be
1981
- // relied upon even though it is not a documented guarantee at all of
1982
- // the `HashMap` type. In any case we've decided that this is reasonable
1983
- // for now, so caching keys thread-locally seems fine.
1984
- thread_local ! ( static KEYS : ( u64 , u64 ) = {
1985
- let r = rand:: OsRng :: new( ) ;
1986
- let mut r = r. expect( "failed to create an OS RNG" ) ;
1987
- ( r. gen ( ) , r. gen ( ) )
1988
- } ) ;
1989
-
1990
- KEYS . with ( |& ( k0, k1) | {
1991
- RandomState { k0 : k0, k1 : k1 }
1992
- } )
1966
+ let mut r = rand:: thread_rng ( ) ;
1967
+ RandomState { k0 : r. gen ( ) , k1 : r. gen ( ) }
1993
1968
}
1994
1969
}
1995
1970
0 commit comments