Skip to content

Commit

Permalink
fix: set in_use to true while cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Aug 10, 2023
1 parent 9dfd219 commit 64154a3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ impl<K: Eq + Hash, V, S: Default> Default for FrozenIndexMap<K, V, S> {

impl<K: Clone, V: Clone, S: Clone> Clone for FrozenIndexMap<K, V, S> {
fn clone(&self) -> Self {
Self {
assert!(!self.in_use.get());
self.in_use.set(true);
let self_clone = Self {
map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(),
in_use: self.in_use.clone(),
}
in_use: Cell::from(false),
};
self.in_use.set(false);
return self_clone;
}
}
10 changes: 7 additions & 3 deletions src/index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ impl<T: Eq + Hash, S: Default> Default for FrozenIndexSet<T, S> {

impl<K: Clone, V: Clone> Clone for FrozenIndexSet<K, V> {
fn clone(&self) -> Self {
Self {
assert!(!self.in_use.get());
self.in_use.set(true);
let self_clone = Self {
set: unsafe { self.set.get().as_ref().unwrap() }.clone().into(),
in_use: self.in_use.clone(),
}
in_use: Cell::from(false),
};
self.in_use.set(false);
return self_clone;
}
}
22 changes: 14 additions & 8 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,14 @@ impl<K: Eq + Hash, V, S: Default> Default for FrozenMap<K, V, S> {

impl<K: Clone, V: Clone, S: Clone> Clone for FrozenMap<K, V, S> {
fn clone(&self) -> Self {
Self {
assert!(!self.in_use.get());
self.in_use.set(true);
let self_clone = Self {
map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(),
in_use: self.in_use.clone(),
}
}
in_use: Cell::from(false),
};
self.in_use.set(false);
return self_clone;}
}

/// Append-only version of `std::collections::BTreeMap` where
Expand Down Expand Up @@ -507,9 +510,12 @@ impl<K: Clone + Ord, V: StableDeref> Default for FrozenBTreeMap<K, V> {

impl<K: Clone, V: Clone> Clone for FrozenBTreeMap<K, V> {
fn clone(&self) -> Self {
Self {
assert!(!self.in_use.get());
self.in_use.set(true);
let self_clone = Self {
map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(),
in_use: self.in_use.clone(),
}
}
in_use: Cell::from(false),
};
self.in_use.set(false);
return self_clone;}
}

0 comments on commit 64154a3

Please sign in to comment.