Auto merge of #19787 - emilio:opt-has-class, r=bholley

style: Make GeckoElement::has_class faster.

By force-inlining the fast path, and pulling out a branch that rust didn't manage to pull out.

<!-- 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/19787)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-01-16 15:15:01 -06:00 committed by GitHub
commit 1ac35dc7ab
2 changed files with 9 additions and 2 deletions

View file

@ -32,7 +32,14 @@ pub fn has_class<T>(
1 => case_sensitivity.eq_atom(name, WeakAtom::new(class)),
n => {
let classes = slice::from_raw_parts(list, n as usize);
classes.iter().any(|ptr| case_sensitivity.eq_atom(name, WeakAtom::new(*ptr)))
match case_sensitivity {
CaseSensitivity::CaseSensitive => {
classes.iter().any(|ptr| &**name == WeakAtom::new(*ptr))
}
CaseSensitivity::AsciiCaseInsensitive => {
classes.iter().any(|ptr| name.eq_ignore_ascii_case(WeakAtom::new(*ptr)))
}
}
}
}
}

View file

@ -2191,7 +2191,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
}
}
#[inline]
#[inline(always)]
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
if !self.may_have_class() {
return false;