@@ -8,6 +8,7 @@ mod util;
8
8
#[ cfg( feature = "serde" ) ]
9
9
mod serde;
10
10
11
+ use cfg_if:: cfg_if;
11
12
use fxhash:: FxBuildHasher ;
12
13
use iter:: { Iter , IterMut } ;
13
14
use mapref:: entry:: { Entry , OccupiedEntry , VacantEntry } ;
@@ -19,7 +20,6 @@ use std::iter::FromIterator;
19
20
use std:: ops:: { BitAnd , BitOr , Shl , Shr , Sub } ;
20
21
use t:: Map ;
21
22
use util:: SharedValue ;
22
- use cfg_if:: cfg_if;
23
23
24
24
type HashMap < K , V > = std:: collections:: HashMap < K , SharedValue < V > , FxBuildHasher > ;
25
25
@@ -121,6 +121,12 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
121
121
pub fn shards( & self ) -> & [ RwLock <HashMap <K , V >>] {
122
122
& self . shards
123
123
}
124
+ } else {
125
+ #[ allow( dead_code) ]
126
+ #[ inline]
127
+ fn shards( & self ) -> & [ RwLock <HashMap <K , V >>] {
128
+ & self . shards
129
+ }
124
130
}
125
131
}
126
132
@@ -146,7 +152,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
146
152
{
147
153
let hash = fxhash:: hash64( & key) ;
148
154
let shift = util:: ptr_size_bits( ) - self . ncb;
149
-
155
+
150
156
( hash >> shift) as usize
151
157
}
152
158
} else {
@@ -158,11 +164,11 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
158
164
{
159
165
let hash = fxhash:: hash64( & key) ;
160
166
let shift = util:: ptr_size_bits( ) - self . ncb;
161
-
167
+
162
168
( hash >> shift) as usize
163
169
}
164
170
}
165
- }
171
+ }
166
172
167
173
/// Inserts a key and a value into the map.
168
174
///
@@ -368,9 +374,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
368
374
/// stats.alter("Goals", |_, v| v * 2);
369
375
/// assert_eq!(*stats.get("Goals").unwrap(), 8);
370
376
/// ```
371
- ///
377
+ ///
372
378
/// # Panics
373
- ///
379
+ ///
374
380
/// If the given closure panics, then `alter_all` will abort the process
375
381
#[ inline]
376
382
pub fn alter < Q > ( & self , key : & Q , f : impl FnOnce ( & K , V ) -> V )
@@ -395,9 +401,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
395
401
/// assert_eq!(*stats.get("Wins").unwrap(), 5);
396
402
/// assert_eq!(*stats.get("Losses").unwrap(), 3);
397
403
/// ```
398
- ///
404
+ ///
399
405
/// # Panics
400
- ///
406
+ ///
401
407
/// If the given closure panics, then `alter_all` will abort the process
402
408
#[ inline]
403
409
pub fn alter_all ( & self , f : impl FnMut ( & K , V ) -> V ) {
@@ -454,7 +460,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> Map<'a, K, V> for DashMap<K, V> {
454
460
fn _insert ( & self , key : K , value : V ) -> Option < V > {
455
461
let idx = self . determine_map ( & key) ;
456
462
let mut shard = unsafe { self . _yield_write_shard ( idx) } ;
457
- shard. insert ( key, SharedValue :: new ( value) ) . map ( SharedValue :: into_inner)
463
+ shard
464
+ . insert ( key, SharedValue :: new ( value) )
465
+ . map ( SharedValue :: into_inner)
458
466
}
459
467
460
468
#[ inline]
@@ -523,7 +531,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> Map<'a, K, V> for DashMap<K, V> {
523
531
524
532
#[ inline]
525
533
fn _retain ( & self , mut f : impl FnMut ( & K , & mut V ) -> bool ) {
526
- self . shards . iter ( ) . for_each ( |s| s. write ( ) . retain ( |k, v| f ( k, v. get_mut ( ) ) ) ) ;
534
+ self . shards
535
+ . iter ( )
536
+ . for_each ( |s| s. write ( ) . retain ( |k, v| f ( k, v. get_mut ( ) ) ) ) ;
527
537
}
528
538
529
539
#[ inline]
0 commit comments