Auto merge of #16934 - bzbarsky:check-snapshot-id-class-flags, r=emilio

Check snapshot id/class flags before looking for those attributes.

<!-- Please describe your changes on the following line: -->
Most elements don't have classes or IDs.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1365659

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because they are just performance optimization

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16934)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-18 11:40:51 -05:00 committed by GitHub
commit 2fd7f4f393
3 changed files with 888 additions and 782 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

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)