Use snapshot class/id flags to optimize out class/id gets.

This commit is contained in:
Boris Zbarsky 2017-05-18 11:32:49 -04:00
parent 8783254d3d
commit b9a0737946

View file

@ -148,7 +148,12 @@ impl ElementSnapshot for GeckoElementSnapshot {
self.has_any(Flags::Attributes) self.has_any(Flags::Attributes)
} }
#[inline]
fn id_attr(&self) -> Option<Atom> { fn id_attr(&self) -> Option<Atom> {
if !self.has_any(Flags::Id) {
return None
}
let ptr = unsafe { let ptr = unsafe {
bindings::Gecko_SnapshotAtomAttrValue(self, bindings::Gecko_SnapshotAtomAttrValue(self,
atom!("id").as_ptr()) atom!("id").as_ptr())
@ -161,15 +166,25 @@ impl ElementSnapshot for GeckoElementSnapshot {
} }
} }
#[inline]
fn has_class(&self, name: &Atom) -> bool { fn has_class(&self, name: &Atom) -> bool {
if !self.has_any(Flags::MaybeClass) {
return false;
}
snapshot_helpers::has_class(self.as_ptr(), snapshot_helpers::has_class(self.as_ptr(),
name, name,
bindings::Gecko_SnapshotClassOrClassList) bindings::Gecko_SnapshotClassOrClassList)
} }
#[inline]
fn each_class<F>(&self, callback: F) fn each_class<F>(&self, callback: F)
where F: FnMut(&Atom) where F: FnMut(&Atom)
{ {
if !self.has_any(Flags::MaybeClass) {
return;
}
snapshot_helpers::each_class(self.as_ptr(), snapshot_helpers::each_class(self.as_ptr(),
callback, callback,
bindings::Gecko_SnapshotClassOrClassList) bindings::Gecko_SnapshotClassOrClassList)