From fe59b62db7e342abdc7b706a633ec4cfb9448b1b Mon Sep 17 00:00:00 2001 From: Rohan Prinja Date: Sat, 24 Oct 2015 01:42:22 +0900 Subject: [PATCH] make changes according to code review (#8097) --- components/script/dom/bindings/js.rs | 41 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 3e4cfeb0fce..66d3074edc7 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -251,11 +251,6 @@ impl MutHeap> { ptr::read(self.val.get()).root() } } - - /// Compare this object to an `&T` value. - fn eq(&self, other: &T) -> bool { - self.get() == Root::from_ref(other) - } } impl HeapSizeOf for MutHeap { @@ -267,7 +262,17 @@ impl HeapSizeOf for MutHeap { impl PartialEq for MutHeap> { fn eq(&self, other: &Self) -> bool { - self.get().eq(&other.get()) + unsafe { + *self.val.get() == *other.val.get() + } + } +} + +impl PartialEq for MutHeap> { + fn eq(&self, other: &T) -> bool { + unsafe { + *self.val.get() == JS::from_ref(other) + } } } @@ -331,9 +336,21 @@ impl MutNullableHeap> { } } - /// Compare this object to an `Option<&T>` value. - fn equal(&self, other: Option<&T>) -> bool { - self.get() == other.map(|p| Root::from_ref(p)) +} + +impl PartialEq for MutNullableHeap> { + fn eq(&self, other: &Self) -> bool { + unsafe { + *self.ptr.get() == *other.ptr.get() + } + } +} + +impl<'a, T: Reflectable> PartialEq> for MutNullableHeap> { + fn eq(&self, other: &Option<&T>) -> bool { + unsafe { + *self.ptr.get() == other.map(|p| JS::from_ref(p)) + } } } @@ -353,12 +370,6 @@ impl HeapSizeOf for MutNullableHeap { } } -impl PartialEq for MutNullableHeap> { - fn eq(&self, other: &Self) -> bool { - self.get().eq(&other.get()) - } -} - impl LayoutJS { /// Returns an unsafe pointer to the interior of this JS object. This is /// the only method that be safely accessed from layout. (The fact that