Skip to content

Commit

Permalink
Merge pull request #72 from aminya/partial-eq-fixes
Browse files Browse the repository at this point in the history
Fixes for PartialEq for frozen map and vec
  • Loading branch information
Manishearth authored Nov 20, 2023
2 parents 636db2b + 410b6d6 commit 77916c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<T: Hash + Eq, S: PartialEq> PartialEq for FrozenIndexMap<T, S> {
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = unsafe { *self.map.get() == *other.map.get() };
let ret = unsafe { self.map.get().as_ref() == other.map.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
Expand Down
2 changes: 1 addition & 1 deletion src/index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<T: Hash + Eq, S: BuildHasher> PartialEq for FrozenIndexSet<T, S> {
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = unsafe { *self.set.get() == *other.set.get() };
let ret = unsafe { self.set.get().as_ref() == other.set.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
Expand Down
17 changes: 15 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ impl<K: Clone, V: Clone, S: Clone> Clone for FrozenMap<K, V, S> {
}
}

impl<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenMap<K, V> {
fn eq(&self, other: &Self) -> bool {
assert!(!self.in_use.get());
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = unsafe { self.map.get().as_ref() == other.map.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
}
}

/// Append-only version of `std::collections::BTreeMap` where
/// insertion does not require mutable access
pub struct FrozenBTreeMap<K, V> {
Expand Down Expand Up @@ -522,13 +535,13 @@ impl<K: Clone, V: Clone> Clone for FrozenBTreeMap<K, V> {
}
}

impl<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenMap<K, V> {
impl<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenBTreeMap<K, V> {
fn eq(&self, other: &Self) -> bool {
assert!(!self.in_use.get());
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = self.map.get() == other.map.get();
let ret = unsafe { self.map.get().as_ref() == other.map.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
Expand Down
4 changes: 2 additions & 2 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ impl<'a, T: StableDeref> IntoIterator for &'a FrozenVec<T> {
}
}

impl<T: StableDeref> PartialEq for FrozenVec<T>
impl<T: StableDeref + PartialEq> PartialEq for FrozenVec<T>
where
T::Target: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.vec.get() == other.vec.get()
unsafe { self.vec.get().as_ref() == other.vec.get().as_ref() }
}
}

Expand Down

0 comments on commit 77916c0

Please sign in to comment.