diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-11-22 01:02:22 +0000 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-02-26 16:44:05 +0100 |
commit | 9f40b9ba38a531088c2117b955f40af6ea0d09c8 (patch) | |
tree | e221662df58ec16b2c2027d71fd5df015fe3f526 /components/style/gecko/snapshot_helpers.rs | |
parent | 4ea378a6ae232af09135b2037c527466ef5454de (diff) | |
download | servo-9f40b9ba38a531088c2117b955f40af6ea0d09c8.tar.gz servo-9f40b9ba38a531088c2117b955f40af6ea0d09c8.zip |
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
Diffstat (limited to 'components/style/gecko/snapshot_helpers.rs')
-rw-r--r-- | components/style/gecko/snapshot_helpers.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/components/style/gecko/snapshot_helpers.rs b/components/style/gecko/snapshot_helpers.rs index bd905870353..ee8d7dfd704 100644 --- a/components/style/gecko/snapshot_helpers.rs +++ b/components/style/gecko/snapshot_helpers.rs @@ -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) } }, } |