mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Avoid some allocations in selector serialization.
The allocations in display_to_css_identifier show up in the profiles of bug 1675628. Differential Revision: https://phabricator.services.mozilla.com/D97856
This commit is contained in:
parent
4ea378a6ae
commit
9f40b9ba38
19 changed files with 220 additions and 114 deletions
|
@ -6,7 +6,9 @@
|
|||
|
||||
use crate::gecko_bindings::bindings;
|
||||
use crate::gecko_bindings::structs::{self, nsAtom};
|
||||
use crate::string_cache::{Atom, WeakAtom};
|
||||
use crate::string_cache::WeakAtom;
|
||||
use crate::values::AtomIdent;
|
||||
use crate::Atom;
|
||||
use crate::CaseSensitivityExt;
|
||||
use selectors::attr::CaseSensitivity;
|
||||
|
||||
|
@ -85,8 +87,8 @@ pub fn get_id(attrs: &[structs::AttrArray_InternalAttr]) -> Option<&WeakAtom> {
|
|||
#[inline(always)]
|
||||
pub(super) fn each_exported_part(
|
||||
attrs: &[structs::AttrArray_InternalAttr],
|
||||
name: &Atom,
|
||||
mut callback: impl FnMut(&Atom),
|
||||
name: &AtomIdent,
|
||||
mut callback: impl FnMut(&AtomIdent),
|
||||
) {
|
||||
let attr = match find_attr(attrs, &atom!("exportparts")) {
|
||||
Some(attr) => attr,
|
||||
|
@ -100,7 +102,7 @@ pub(super) fn each_exported_part(
|
|||
|
||||
unsafe {
|
||||
for atom in std::slice::from_raw_parts(atoms, length) {
|
||||
Atom::with(*atom, &mut callback)
|
||||
AtomIdent::with(*atom, &mut callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,21 +110,21 @@ pub(super) fn each_exported_part(
|
|||
#[inline(always)]
|
||||
pub(super) fn imported_part(
|
||||
attrs: &[structs::AttrArray_InternalAttr],
|
||||
name: &Atom,
|
||||
) -> Option<Atom> {
|
||||
name: &AtomIdent,
|
||||
) -> Option<AtomIdent> {
|
||||
let attr = find_attr(attrs, &atom!("exportparts"))?;
|
||||
let atom = unsafe { bindings::Gecko_Element_ImportedPart(attr, name.as_ptr()) };
|
||||
if atom.is_null() {
|
||||
return None;
|
||||
}
|
||||
Some(unsafe { Atom::from_raw(atom) })
|
||||
Some(AtomIdent(unsafe { Atom::from_raw(atom) }))
|
||||
}
|
||||
|
||||
/// Given a class or part name, a case sensitivity, and an array of attributes,
|
||||
/// returns whether the attribute has that name.
|
||||
#[inline(always)]
|
||||
pub fn has_class_or_part(
|
||||
name: &Atom,
|
||||
name: &AtomIdent,
|
||||
case_sensitivity: CaseSensitivity,
|
||||
attr: &structs::nsAttrValue,
|
||||
) -> bool {
|
||||
|
@ -147,15 +149,15 @@ pub fn has_class_or_part(
|
|||
#[inline(always)]
|
||||
pub fn each_class_or_part<F>(attr: &structs::nsAttrValue, mut callback: F)
|
||||
where
|
||||
F: FnMut(&Atom),
|
||||
F: FnMut(&AtomIdent),
|
||||
{
|
||||
unsafe {
|
||||
match get_class_or_part_from_attr(attr) {
|
||||
Class::None => {},
|
||||
Class::One(atom) => Atom::with(atom, callback),
|
||||
Class::One(atom) => AtomIdent::with(atom, callback),
|
||||
Class::More(atoms) => {
|
||||
for atom in atoms {
|
||||
Atom::with(atom.mRawPtr, &mut callback)
|
||||
AtomIdent::with(atom.mRawPtr, &mut callback)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue