mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #19454 - emilio:has-class-is-stupid, r=upsuper
style: Add a missing fast-path in GeckoElement::each_class. This shows up when inserting elements in the bloom filter. <!-- 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/19454) <!-- Reviewable:end -->
This commit is contained in:
commit
45bbbac9d9
2 changed files with 23 additions and 13 deletions
|
@ -17,11 +17,12 @@ pub type ClassOrClassList<T> = unsafe extern fn (T, *mut *mut nsAtom, *mut *mut
|
|||
|
||||
/// Given an item `T`, a class name, and a getter function, return whether that
|
||||
/// element has the class that `name` represents.
|
||||
pub fn has_class<T>(item: T,
|
||||
pub fn has_class<T>(
|
||||
item: T,
|
||||
name: &Atom,
|
||||
case_sensitivity: CaseSensitivity,
|
||||
getter: ClassOrClassList<T>) -> bool
|
||||
{
|
||||
getter: ClassOrClassList<T>,
|
||||
) -> bool {
|
||||
unsafe {
|
||||
let mut class: *mut nsAtom = ptr::null_mut();
|
||||
let mut list: *mut *mut nsAtom = ptr::null_mut();
|
||||
|
@ -40,10 +41,13 @@ pub fn has_class<T>(item: T,
|
|||
|
||||
/// Given an item, a callback, and a getter, execute `callback` for each class
|
||||
/// this `item` has.
|
||||
pub fn each_class<F, T>(item: T,
|
||||
pub fn each_class<F, T>(
|
||||
item: T,
|
||||
mut callback: F,
|
||||
getter: ClassOrClassList<T>)
|
||||
where F: FnMut(&Atom)
|
||||
getter: ClassOrClassList<T>,
|
||||
)
|
||||
where
|
||||
F: FnMut(&Atom)
|
||||
{
|
||||
unsafe {
|
||||
let mut class: *mut nsAtom = ptr::null_mut();
|
||||
|
|
|
@ -1113,6 +1113,10 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
where
|
||||
F: FnMut(&Atom),
|
||||
{
|
||||
if !self.may_have_class() {
|
||||
return;
|
||||
}
|
||||
|
||||
snapshot_helpers::each_class(self.0, callback, Gecko_ClassOrClassList)
|
||||
}
|
||||
|
||||
|
@ -2129,10 +2133,12 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
return false;
|
||||
}
|
||||
|
||||
snapshot_helpers::has_class(self.0,
|
||||
snapshot_helpers::has_class(
|
||||
self.0,
|
||||
name,
|
||||
case_sensitivity,
|
||||
Gecko_ClassOrClassList)
|
||||
Gecko_ClassOrClassList,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue