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
This commit is contained in:
Emilio Cobos Álvarez 2017-11-15 03:30:43 +01:00
parent 2efbf2230a
commit 28c04278e1
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 28 additions and 0 deletions

View file

@ -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 { fn select_name<'a, T>(is_html: bool, local_name: &'a T, local_name_lower: &'a T) -> &'a T {
if is_html { if is_html {
local_name_lower local_name_lower

View file

@ -423,6 +423,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
/// Whether this selector (pseudo-element part excluded) matches every element. /// Whether this selector (pseudo-element part excluded) matches every element.
/// ///
/// Used for "pre-computed" pseudo-elements in components/style/stylist.rs /// Used for "pre-computed" pseudo-elements in components/style/stylist.rs
#[inline]
pub fn is_universal(&self) -> bool { pub fn is_universal(&self) -> bool {
self.iter_raw_match_order().all(|c| matches!(*c, self.iter_raw_match_order().all(|c| matches!(*c,
Component::ExplicitUniversalType | Component::ExplicitUniversalType |
@ -435,6 +436,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
/// Returns an iterator over this selector in matching order (right-to-left). /// Returns an iterator over this selector in matching order (right-to-left).
/// When a combinator is reached, the iterator will return None, and /// When a combinator is reached, the iterator will return None, and
/// next_sequence() may be called to continue to the next sequence. /// next_sequence() may be called to continue to the next sequence.
#[inline]
pub fn iter(&self) -> SelectorIter<Impl> { pub fn iter(&self) -> SelectorIter<Impl> {
SelectorIter { SelectorIter {
iter: self.iter_raw_match_order(), 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), /// Returns an iterator over this selector in matching order (right-to-left),
/// skipping the rightmost |offset| Components. /// skipping the rightmost |offset| Components.
#[inline]
pub fn iter_from(&self, offset: usize) -> SelectorIter<Impl> { pub fn iter_from(&self, offset: usize) -> SelectorIter<Impl> {
let iter = self.0.slice[offset..].iter(); let iter = self.0.slice[offset..].iter();
SelectorIter { SelectorIter {
@ -467,6 +470,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
/// Returns an iterator over the entire sequence of simple selectors and /// Returns an iterator over the entire sequence of simple selectors and
/// combinators, in matching order (from right to left). /// combinators, in matching order (from right to left).
#[inline]
pub fn iter_raw_match_order(&self) -> slice::Iter<Component<Impl>> { pub fn iter_raw_match_order(&self) -> slice::Iter<Component<Impl>> {
self.0.slice.iter() self.0.slice.iter()
} }
@ -487,6 +491,7 @@ impl<Impl: SelectorImpl> Selector<Impl> {
/// Returns an iterator over the sequence of simple selectors and /// Returns an iterator over the sequence of simple selectors and
/// combinators, in parse order (from left to right), starting from /// combinators, in parse order (from left to right), starting from
/// `offset`. /// `offset`.
#[inline]
pub fn iter_raw_parse_order_from(&self, offset: usize) -> Rev<slice::Iter<Component<Impl>>> { pub fn iter_raw_parse_order_from(&self, offset: usize) -> Rev<slice::Iter<Component<Impl>>> {
self.0.slice[..self.len() - offset].iter().rev() 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. /// Returns count of simple selectors and combinators in the Selector.
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.slice.len() self.0.slice.len()
} }
@ -525,11 +531,13 @@ pub struct SelectorIter<'a, Impl: 'a + SelectorImpl> {
impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> { impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> {
/// Prepares this iterator to point to the next sequence to the left, /// Prepares this iterator to point to the next sequence to the left,
/// returning the combinator if the sequence was found. /// returning the combinator if the sequence was found.
#[inline]
pub fn next_sequence(&mut self) -> Option<Combinator> { pub fn next_sequence(&mut self) -> Option<Combinator> {
self.next_combinator.take() self.next_combinator.take()
} }
/// Returns remaining count of the simple selectors and combinators in the Selector. /// Returns remaining count of the simple selectors and combinators in the Selector.
#[inline]
pub fn selector_length(&self) -> usize { pub fn selector_length(&self) -> usize {
self.iter.len() self.iter.len()
} }
@ -537,6 +545,8 @@ impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> {
impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> { impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> {
type Item = &'a Component<Impl>; type Item = &'a Component<Impl>;
#[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
debug_assert!(self.next_combinator.is_none(), debug_assert!(self.next_combinator.is_none(),
"You should call next_sequence!"); "You should call next_sequence!");
@ -624,6 +634,7 @@ pub enum Combinator {
impl Combinator { impl Combinator {
/// Returns true if this combinator is a child or descendant combinator. /// Returns true if this combinator is a child or descendant combinator.
#[inline]
pub fn is_ancestor(&self) -> bool { pub fn is_ancestor(&self) -> bool {
matches!(*self, Combinator::Child | matches!(*self, Combinator::Child |
Combinator::Descendant | Combinator::Descendant |
@ -631,11 +642,13 @@ impl Combinator {
} }
/// Returns true if this combinator is a pseudo-element combinator. /// Returns true if this combinator is a pseudo-element combinator.
#[inline]
pub fn is_pseudo_element(&self) -> bool { pub fn is_pseudo_element(&self) -> bool {
matches!(*self, Combinator::PseudoElement) matches!(*self, Combinator::PseudoElement)
} }
/// Returns true if this combinator is a next- or later-sibling combinator. /// Returns true if this combinator is a next- or later-sibling combinator.
#[inline]
pub fn is_sibling(&self) -> bool { pub fn is_sibling(&self) -> bool {
matches!(*self, Combinator::NextSibling | Combinator::LaterSibling) matches!(*self, Combinator::NextSibling | Combinator::LaterSibling)
} }

View file

@ -99,14 +99,17 @@ pub struct GeckoDocument<'ld>(pub &'ld structs::nsIDocument);
impl<'ld> TDocument for GeckoDocument<'ld> { impl<'ld> TDocument for GeckoDocument<'ld> {
type ConcreteNode = GeckoNode<'ld>; type ConcreteNode = GeckoNode<'ld>;
#[inline]
fn as_node(&self) -> Self::ConcreteNode { fn as_node(&self) -> Self::ConcreteNode {
GeckoNode(&self.0._base) GeckoNode(&self.0._base)
} }
#[inline]
fn is_html_document(&self) -> bool { fn is_html_document(&self) -> bool {
self.0.mType == structs::root::nsIDocument_Type::eHTML self.0.mType == structs::root::nsIDocument_Type::eHTML
} }
#[inline]
fn quirks_mode(&self) -> QuirksMode { fn quirks_mode(&self) -> QuirksMode {
self.0.mCompatMode.into() self.0.mCompatMode.into()
} }
@ -144,6 +147,7 @@ impl<'ld> TDocument for GeckoDocument<'ld> {
pub struct GeckoNode<'ln>(pub &'ln RawGeckoNode); pub struct GeckoNode<'ln>(pub &'ln RawGeckoNode);
impl<'ln> PartialEq for GeckoNode<'ln> { impl<'ln> PartialEq for GeckoNode<'ln> {
#[inline]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.0 as *const _ == other.0 as *const _ 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()) self.flattened_tree_parent().and_then(|n| n.as_element())
} }
#[inline]
fn opaque(&self) -> OpaqueNode { fn opaque(&self) -> OpaqueNode {
let ptr: usize = self.0 as *const _ as usize; let ptr: usize = self.0 as *const _ as usize;
OpaqueNode(ptr) OpaqueNode(ptr)
@ -329,6 +334,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
} }
} }
#[inline]
fn can_be_fragmented(&self) -> bool { fn can_be_fragmented(&self) -> bool {
// FIXME(SimonSapin): Servo uses this to implement CSS multicol / fragmentation // FIXME(SimonSapin): Servo uses this to implement CSS multicol / fragmentation
// Maybe this isnt useful for Gecko? // Maybe this isnt useful for Gecko?
@ -397,14 +403,17 @@ impl<'a> Iterator for GeckoChildrenIterator<'a> {
pub struct GeckoXBLBinding<'lb>(pub &'lb RawGeckoXBLBinding); pub struct GeckoXBLBinding<'lb>(pub &'lb RawGeckoXBLBinding);
impl<'lb> GeckoXBLBinding<'lb> { impl<'lb> GeckoXBLBinding<'lb> {
#[inline]
fn base_binding(&self) -> Option<Self> { fn base_binding(&self) -> Option<Self> {
unsafe { self.0.mNextBinding.mRawPtr.as_ref().map(GeckoXBLBinding) } unsafe { self.0.mNextBinding.mRawPtr.as_ref().map(GeckoXBLBinding) }
} }
#[inline]
fn anon_content(&self) -> *const nsIContent { fn anon_content(&self) -> *const nsIContent {
unsafe { self.0.mContent.raw::<nsIContent>() } unsafe { self.0.mContent.raw::<nsIContent>() }
} }
#[inline]
fn inherits_style(&self) -> bool { fn inherits_style(&self) -> bool {
unsafe { bindings::Gecko_XBLBinding_InheritsStyle(self.0) } unsafe { bindings::Gecko_XBLBinding_InheritsStyle(self.0) }
} }
@ -1024,6 +1033,7 @@ impl<'le> TElement for GeckoElement<'le> {
} }
} }
#[inline]
fn as_node(&self) -> Self::ConcreteNode { fn as_node(&self) -> Self::ConcreteNode {
unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) } 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) get_animation_rule(self, CascadeLevel::Transitions)
} }
#[inline]
fn get_state(&self) -> ElementState { fn get_state(&self) -> ElementState {
ElementState::from_bits_truncate(self.get_state_internal()) ElementState::from_bits_truncate(self.get_state_internal())
} }
@ -1752,6 +1763,7 @@ impl<'le> TElement for GeckoElement<'le> {
} }
impl<'le> PartialEq for GeckoElement<'le> { impl<'le> PartialEq for GeckoElement<'le> {
#[inline]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.0 as *const _ == other.0 as *const _ self.0 as *const _ == other.0 as *const _
} }
@ -1760,6 +1772,7 @@ impl<'le> PartialEq for GeckoElement<'le> {
impl<'le> Eq for GeckoElement<'le> {} impl<'le> Eq for GeckoElement<'le> {}
impl<'le> Hash for GeckoElement<'le> { impl<'le> Hash for GeckoElement<'le> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
(self.0 as *const _).hash(state); (self.0 as *const _).hash(state);
} }
@ -1902,6 +1915,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
} }
} }
#[inline]
fn is_root(&self) -> bool { fn is_root(&self) -> bool {
unsafe { unsafe {
Gecko_IsRootElement(self.0) Gecko_IsRootElement(self.0)