Skip to content

Commit

Permalink
more efficiently create dash-map
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtgs committed Aug 21, 2024
1 parent 633aadb commit 8a798a6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct DashMap<K, V, S = RandomState> {

impl<K: Eq + Hash + Clone, V: Clone, S: Clone> Clone for DashMap<K, V, S> {
fn clone(&self) -> Self {
let mut inner_shards = Vec::new();
let mut inner_shards = Vec::with_capacity(self.shards.len());

for shard in self.shards.iter() {
let shard = shard.read();
Expand Down Expand Up @@ -282,9 +282,8 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap<K, V, S> {

let cps = capacity / shard_amount;

let shards = (0..shard_amount)
.map(|_| CachePadded::new(RwLock::new(HashMap::with_capacity(cps))))
.collect();
let shards = vec![CachePadded::new(RwLock::new(HashMap::with_capacity(cps))); shard_amount]
.into_boxed_slice();

Self {
shift,
Expand Down

0 comments on commit 8a798a6

Please sign in to comment.