Bug 1365659 part 3. Use snapshot id/class flags on the servo side to optimize id/class access on snapshots. r=emilio
MozReview-Commit-ID: 4J1E1Y8yaqn
--- a/servo/components/style/gecko/snapshot.rs
+++ b/servo/components/style/gecko/snapshot.rs
@@ -143,35 +143,49 @@ impl ElementSnapshot for GeckoElementSna
}
}
#[inline]
fn has_attrs(&self) -> bool {
self.has_any(Flags::Attributes)
}
+ #[inline]
fn id_attr(&self) -> Option<Atom> {
+ if !self.has_any(Flags::Id) {
+ return None
+ }
+
let ptr = unsafe {
bindings::Gecko_SnapshotAtomAttrValue(self,
atom!("id").as_ptr())
};
if ptr.is_null() {
None
} else {
Some(Atom::from(ptr))
}
}
+ #[inline]
fn has_class(&self, name: &Atom) -> bool {
- snapshot_helpers::has_class(self.as_ptr(),
- name,
- bindings::Gecko_SnapshotClassOrClassList)
+ if self.has_any(Flags::MaybeClass) {
+ snapshot_helpers::has_class(self.as_ptr(),
+ name,
+ bindings::Gecko_SnapshotClassOrClassList)
+ } else {
+ false
+ }
}
+ #[inline]
fn each_class<F>(&self, callback: F)
where F: FnMut(&Atom)
{
+ if !self.has_any(Flags::MaybeClass) {
+ return;
+ }
snapshot_helpers::each_class(self.as_ptr(),
callback,
bindings::Gecko_SnapshotClassOrClassList)
}
}