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 Sep 23, 2023
1 parent 3724407 commit a4f7b0a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 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;
}
}
20 changes: 14 additions & 6 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +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;
}
}

Expand Down Expand Up @@ -507,9 +511,13 @@ 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;
}
}
1 change: 0 additions & 1 deletion src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ impl<T: Clone> Clone for FrozenVec<T> {
}
}


impl<T> From<Vec<T>> for FrozenVec<T> {
fn from(vec: Vec<T>) -> Self {
Self {
Expand Down

0 comments on commit a4f7b0a

Please sign in to comment.