Skip to content

Commit

Permalink
Got bitten by a macro bug. v3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xacrimon committed Jan 15, 2020
1 parent ae970f5 commit 0a5746d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dashmap"
version = "3.0.4"
version = "3.0.5"
authors = ["Acrimon <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::mapref::multiple::{RefMulti, RefMutMulti};
use super::util;
use crate::t::Map;
use crate::HashMap;
use crate::util::SharedValue;
use crate::HashMap;
use parking_lot::{RwLockReadGuard, RwLockWriteGuard};
use std::collections::hash_map;
use std::hash::Hash;
Expand Down
30 changes: 20 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod util;
#[cfg(feature = "serde")]
mod serde;

use cfg_if::cfg_if;
use fxhash::FxBuildHasher;
use iter::{Iter, IterMut};
use mapref::entry::{Entry, OccupiedEntry, VacantEntry};
Expand All @@ -19,7 +20,6 @@ use std::iter::FromIterator;
use std::ops::{BitAnd, BitOr, Shl, Shr, Sub};
use t::Map;
use util::SharedValue;
use cfg_if::cfg_if;

type HashMap<K, V> = std::collections::HashMap<K, SharedValue<V>, FxBuildHasher>;

Expand Down Expand Up @@ -121,6 +121,12 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
pub fn shards(&self) -> &[RwLock<HashMap<K, V>>] {
&self.shards
}
} else {
#[allow(dead_code)]
#[inline]
fn shards(&self) -> &[RwLock<HashMap<K, V>>] {
&self.shards
}
}
}

Expand All @@ -146,7 +152,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
{
let hash = fxhash::hash64(&key);
let shift = util::ptr_size_bits() - self.ncb;

(hash >> shift) as usize
}
} else {
Expand All @@ -158,11 +164,11 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
{
let hash = fxhash::hash64(&key);
let shift = util::ptr_size_bits() - self.ncb;

(hash >> shift) as usize
}
}
}
}

/// Inserts a key and a value into the map.
///
Expand Down Expand Up @@ -368,9 +374,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
/// stats.alter("Goals", |_, v| v * 2);
/// assert_eq!(*stats.get("Goals").unwrap(), 8);
/// ```
///
///
/// # Panics
///
///
/// If the given closure panics, then `alter_all` will abort the process
#[inline]
pub fn alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
Expand All @@ -395,9 +401,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V> {
/// assert_eq!(*stats.get("Wins").unwrap(), 5);
/// assert_eq!(*stats.get("Losses").unwrap(), 3);
/// ```
///
///
/// # Panics
///
///
/// If the given closure panics, then `alter_all` will abort the process
#[inline]
pub fn alter_all(&self, f: impl FnMut(&K, V) -> V) {
Expand Down Expand Up @@ -454,7 +460,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> Map<'a, K, V> for DashMap<K, V> {
fn _insert(&self, key: K, value: V) -> Option<V> {
let idx = self.determine_map(&key);
let mut shard = unsafe { self._yield_write_shard(idx) };
shard.insert(key, SharedValue::new(value)).map(SharedValue::into_inner)
shard
.insert(key, SharedValue::new(value))
.map(SharedValue::into_inner)
}

#[inline]
Expand Down Expand Up @@ -523,7 +531,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a> Map<'a, K, V> for DashMap<K, V> {

#[inline]
fn _retain(&self, mut f: impl FnMut(&K, &mut V) -> bool) {
self.shards.iter().for_each(|s| s.write().retain(|k, v| f(k, v.get_mut())));
self.shards
.iter()
.for_each(|s| s.write().retain(|k, v| f(k, v.get_mut())));
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/mapref/entry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::one::RefMut;
use crate::util;
use crate::HashMap;
use crate::util::SharedValue;
use crate::HashMap;
use parking_lot::RwLockWriteGuard;
use std::hash::Hash;
use std::mem;
Expand Down
6 changes: 3 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This module is full of hackery and dark magic.
//! Either spend a day fixing it and quietly submit a PR or don't mention it to anybody.
use std::{mem, ptr};
use std::cell::UnsafeCell;
use std::{mem, ptr};

#[inline(always)]
pub const fn ptr_size_bits() -> usize {
Expand All @@ -13,7 +13,7 @@ pub const fn ptr_size_bits() -> usize {
pub fn map_in_place_2<T, U, F: FnOnce(U, T) -> T>((k, v): (U, &mut T), f: F) {
unsafe {
// # Safety
//
//
// If the closure panics, we must abort otherwise we could double drop `T`
let _promote_panic_to_abort = AbortOnPanic;

Expand Down Expand Up @@ -78,4 +78,4 @@ impl Drop for AbortOnPanic {
std::process::abort()
}
}
}
}

0 comments on commit 0a5746d

Please sign in to comment.