mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #8097 - wenderen:8090-partialeq-for-mutheap, r=nox
implement PartialEq for MutHeap<JS<T>> and MutNullableHeap<JS<T>> for #8090 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8097) <!-- Reviewable:end -->
This commit is contained in:
commit
6b95c3957b
1 changed files with 33 additions and 0 deletions
|
@ -273,6 +273,22 @@ impl<T: HeapGCValue> HeapSizeOf for MutHeap<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Reflectable> PartialEq for MutHeap<JS<T>> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
unsafe {
|
||||
*self.val.get() == *other.val.get()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Reflectable + PartialEq> PartialEq<T> for MutHeap<JS<T>> {
|
||||
fn eq(&self, other: &T) -> bool {
|
||||
unsafe {
|
||||
**self.val.get() == *other
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A holder that provides interior mutability for GC-managed values such as
|
||||
/// `JS<T>`, with nullability represented by an enclosing Option wrapper.
|
||||
/// Essentially a `Cell<Option<JS<T>>>`, but safer.
|
||||
|
@ -334,6 +350,23 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
|
|||
*self.ptr.get() = val.map(|p| JS::from_ref(p));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<T: Reflectable> PartialEq for MutNullableHeap<JS<T>> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
unsafe {
|
||||
*self.ptr.get() == *other.ptr.get()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Reflectable> PartialEq<Option<&'a T>> for MutNullableHeap<JS<T>> {
|
||||
fn eq(&self, other: &Option<&T>) -> bool {
|
||||
unsafe {
|
||||
*self.ptr.get() == other.map(JS::from_ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HeapGCValue> Default for MutNullableHeap<T> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue