mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #19226 - emilio:inline-qs, r=nox
style: Sprinkle some inline in trivial methods. These methods are instantiated by the Gecko library, and used during querySelector, which means that they end up being super-hot in micro-benchmarks. MozReview-Commit-ID: K1XJb0QyX5a <!-- 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/19226) <!-- Reviewable:end -->
This commit is contained in:
commit
85fa6409bb
3 changed files with 28 additions and 0 deletions
|
@ -800,6 +800,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn select_name<'a, T>(is_html: bool, local_name: &'a T, local_name_lower: &'a T) -> &'a T {
|
||||
if is_html {
|
||||
local_name_lower
|
||||
|
|
|
@ -423,6 +423,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
/// Whether this selector (pseudo-element part excluded) matches every element.
|
||||
///
|
||||
/// Used for "pre-computed" pseudo-elements in components/style/stylist.rs
|
||||
#[inline]
|
||||
pub fn is_universal(&self) -> bool {
|
||||
self.iter_raw_match_order().all(|c| matches!(*c,
|
||||
Component::ExplicitUniversalType |
|
||||
|
@ -435,6 +436,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
/// Returns an iterator over this selector in matching order (right-to-left).
|
||||
/// When a combinator is reached, the iterator will return None, and
|
||||
/// next_sequence() may be called to continue to the next sequence.
|
||||
#[inline]
|
||||
pub fn iter(&self) -> SelectorIter<Impl> {
|
||||
SelectorIter {
|
||||
iter: self.iter_raw_match_order(),
|
||||
|
@ -444,6 +446,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
|
||||
/// Returns an iterator over this selector in matching order (right-to-left),
|
||||
/// skipping the rightmost |offset| Components.
|
||||
#[inline]
|
||||
pub fn iter_from(&self, offset: usize) -> SelectorIter<Impl> {
|
||||
let iter = self.0.slice[offset..].iter();
|
||||
SelectorIter {
|
||||
|
@ -467,6 +470,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
|
||||
/// Returns an iterator over the entire sequence of simple selectors and
|
||||
/// combinators, in matching order (from right to left).
|
||||
#[inline]
|
||||
pub fn iter_raw_match_order(&self) -> slice::Iter<Component<Impl>> {
|
||||
self.0.slice.iter()
|
||||
}
|
||||
|
@ -487,6 +491,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
/// Returns an iterator over the sequence of simple selectors and
|
||||
/// combinators, in parse order (from left to right), starting from
|
||||
/// `offset`.
|
||||
#[inline]
|
||||
pub fn iter_raw_parse_order_from(&self, offset: usize) -> Rev<slice::Iter<Component<Impl>>> {
|
||||
self.0.slice[..self.len() - offset].iter().rev()
|
||||
}
|
||||
|
@ -506,6 +511,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
}
|
||||
|
||||
/// Returns count of simple selectors and combinators in the Selector.
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.slice.len()
|
||||
}
|
||||
|
@ -525,11 +531,13 @@ pub struct SelectorIter<'a, Impl: 'a + SelectorImpl> {
|
|||
impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> {
|
||||
/// Prepares this iterator to point to the next sequence to the left,
|
||||
/// returning the combinator if the sequence was found.
|
||||
#[inline]
|
||||
pub fn next_sequence(&mut self) -> Option<Combinator> {
|
||||
self.next_combinator.take()
|
||||
}
|
||||
|
||||
/// Returns remaining count of the simple selectors and combinators in the Selector.
|
||||
#[inline]
|
||||
pub fn selector_length(&self) -> usize {
|
||||
self.iter.len()
|
||||
}
|
||||
|
@ -537,6 +545,8 @@ impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> {
|
|||
|
||||
impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> {
|
||||
type Item = &'a Component<Impl>;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
debug_assert!(self.next_combinator.is_none(),
|
||||
"You should call next_sequence!");
|
||||
|
@ -624,6 +634,7 @@ pub enum Combinator {
|
|||
|
||||
impl Combinator {
|
||||
/// Returns true if this combinator is a child or descendant combinator.
|
||||
#[inline]
|
||||
pub fn is_ancestor(&self) -> bool {
|
||||
matches!(*self, Combinator::Child |
|
||||
Combinator::Descendant |
|
||||
|
@ -631,11 +642,13 @@ impl Combinator {
|
|||
}
|
||||
|
||||
/// Returns true if this combinator is a pseudo-element combinator.
|
||||
#[inline]
|
||||
pub fn is_pseudo_element(&self) -> bool {
|
||||
matches!(*self, Combinator::PseudoElement)
|
||||
}
|
||||
|
||||
/// Returns true if this combinator is a next- or later-sibling combinator.
|
||||
#[inline]
|
||||
pub fn is_sibling(&self) -> bool {
|
||||
matches!(*self, Combinator::NextSibling | Combinator::LaterSibling)
|
||||
}
|
||||
|
|
|
@ -99,14 +99,17 @@ pub struct GeckoDocument<'ld>(pub &'ld structs::nsIDocument);
|
|||
impl<'ld> TDocument for GeckoDocument<'ld> {
|
||||
type ConcreteNode = GeckoNode<'ld>;
|
||||
|
||||
#[inline]
|
||||
fn as_node(&self) -> Self::ConcreteNode {
|
||||
GeckoNode(&self.0._base)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_html_document(&self) -> bool {
|
||||
self.0.mType == structs::root::nsIDocument_Type::eHTML
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn quirks_mode(&self) -> QuirksMode {
|
||||
self.0.mCompatMode.into()
|
||||
}
|
||||
|
@ -144,6 +147,7 @@ impl<'ld> TDocument for GeckoDocument<'ld> {
|
|||
pub struct GeckoNode<'ln>(pub &'ln RawGeckoNode);
|
||||
|
||||
impl<'ln> PartialEq for GeckoNode<'ln> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 as *const _ == other.0 as *const _
|
||||
}
|
||||
|
@ -302,6 +306,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
|||
self.flattened_tree_parent().and_then(|n| n.as_element())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn opaque(&self) -> OpaqueNode {
|
||||
let ptr: usize = self.0 as *const _ as usize;
|
||||
OpaqueNode(ptr)
|
||||
|
@ -329,6 +334,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn can_be_fragmented(&self) -> bool {
|
||||
// FIXME(SimonSapin): Servo uses this to implement CSS multicol / fragmentation
|
||||
// Maybe this isn’t useful for Gecko?
|
||||
|
@ -397,14 +403,17 @@ impl<'a> Iterator for GeckoChildrenIterator<'a> {
|
|||
pub struct GeckoXBLBinding<'lb>(pub &'lb RawGeckoXBLBinding);
|
||||
|
||||
impl<'lb> GeckoXBLBinding<'lb> {
|
||||
#[inline]
|
||||
fn base_binding(&self) -> Option<Self> {
|
||||
unsafe { self.0.mNextBinding.mRawPtr.as_ref().map(GeckoXBLBinding) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn anon_content(&self) -> *const nsIContent {
|
||||
self.0.mContent.raw::<nsIContent>()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn inherits_style(&self) -> bool {
|
||||
unsafe { bindings::Gecko_XBLBinding_InheritsStyle(self.0) }
|
||||
}
|
||||
|
@ -1024,6 +1033,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_node(&self) -> Self::ConcreteNode {
|
||||
unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) }
|
||||
}
|
||||
|
@ -1080,6 +1090,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
get_animation_rule(self, CascadeLevel::Transitions)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_state(&self) -> ElementState {
|
||||
ElementState::from_bits_truncate(self.get_state_internal())
|
||||
}
|
||||
|
@ -1750,6 +1761,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
}
|
||||
|
||||
impl<'le> PartialEq for GeckoElement<'le> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 as *const _ == other.0 as *const _
|
||||
}
|
||||
|
@ -1758,6 +1770,7 @@ impl<'le> PartialEq for GeckoElement<'le> {
|
|||
impl<'le> Eq for GeckoElement<'le> {}
|
||||
|
||||
impl<'le> Hash for GeckoElement<'le> {
|
||||
#[inline]
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
(self.0 as *const _).hash(state);
|
||||
}
|
||||
|
@ -1900,6 +1913,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_root(&self) -> bool {
|
||||
unsafe {
|
||||
Gecko_IsRootElement(self.0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue