mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
style: Move the single simple selector optimizations to a different function.
MozReview-Commit-ID: EEM3AzW2A9s
This commit is contained in:
parent
db65c2d346
commit
c3876a42a8
1 changed files with 43 additions and 26 deletions
|
@ -10,7 +10,9 @@ use dom::{TDocument, TElement, TNode};
|
||||||
use invalidation::element::invalidator::{Invalidation, InvalidationProcessor, InvalidationVector};
|
use invalidation::element::invalidator::{Invalidation, InvalidationProcessor, InvalidationVector};
|
||||||
use selectors::{Element, NthIndexCache, SelectorList};
|
use selectors::{Element, NthIndexCache, SelectorList};
|
||||||
use selectors::matching::{self, MatchingContext, MatchingMode};
|
use selectors::matching::{self, MatchingContext, MatchingMode};
|
||||||
|
use selectors::parser::{Component, LocalName};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
/// <https://dom.spec.whatwg.org/#dom-element-matches>
|
/// <https://dom.spec.whatwg.org/#dom-element-matches>
|
||||||
pub fn element_matches<E>(
|
pub fn element_matches<E>(
|
||||||
|
@ -218,13 +220,11 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fast paths for a given selector query.
|
|
||||||
///
|
/// Fast paths for querySelector with a single simple selector.
|
||||||
/// FIXME(emilio, nbp): This may very well be a good candidate for code to be
|
fn query_selector_single_query<E, Q>(
|
||||||
/// replaced by HolyJit :)
|
|
||||||
fn query_selector_fast<E, Q>(
|
|
||||||
root: E::ConcreteNode,
|
root: E::ConcreteNode,
|
||||||
selector_list: &SelectorList<E::Impl>,
|
component: &Component<E::Impl>,
|
||||||
results: &mut Q::Output,
|
results: &mut Q::Output,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
|
@ -232,26 +232,6 @@ where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
Q: SelectorQuery<E>,
|
Q: SelectorQuery<E>,
|
||||||
{
|
{
|
||||||
use selectors::parser::{Component, LocalName};
|
|
||||||
use std::borrow::Borrow;
|
|
||||||
|
|
||||||
// We need to return elements in document order, and reordering them
|
|
||||||
// afterwards is kinda silly.
|
|
||||||
if selector_list.0.len() > 1 {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let selector = &selector_list.0[0];
|
|
||||||
|
|
||||||
// Let's just care about the easy cases for now.
|
|
||||||
//
|
|
||||||
// FIXME(emilio): Blink has a fast path for classes in ancestor combinators
|
|
||||||
// that may be worth stealing.
|
|
||||||
if selector.len() > 1 {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let component = selector.iter().next().unwrap();
|
|
||||||
match *component {
|
match *component {
|
||||||
Component::ExplicitUniversalType => {
|
Component::ExplicitUniversalType => {
|
||||||
collect_all_elements::<E, Q, _>(root, results, |_| true)
|
collect_all_elements::<E, Q, _>(root, results, |_| true)
|
||||||
|
@ -287,6 +267,43 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fast paths for a given selector query.
|
||||||
|
///
|
||||||
|
/// FIXME(emilio, nbp): This may very well be a good candidate for code to be
|
||||||
|
/// replaced by HolyJit :)
|
||||||
|
fn query_selector_fast<E, Q>(
|
||||||
|
root: E::ConcreteNode,
|
||||||
|
selector_list: &SelectorList<E::Impl>,
|
||||||
|
results: &mut Q::Output,
|
||||||
|
quirks_mode: QuirksMode,
|
||||||
|
) -> Result<(), ()>
|
||||||
|
where
|
||||||
|
E: TElement,
|
||||||
|
Q: SelectorQuery<E>,
|
||||||
|
{
|
||||||
|
// We need to return elements in document order, and reordering them
|
||||||
|
// afterwards is kinda silly.
|
||||||
|
if selector_list.0.len() > 1 {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let selector = &selector_list.0[0];
|
||||||
|
|
||||||
|
// Let's just care about the easy cases for now.
|
||||||
|
if selector.len() == 1 {
|
||||||
|
return query_selector_single_query::<E, Q>(
|
||||||
|
root,
|
||||||
|
selector.iter().next().unwrap(),
|
||||||
|
results,
|
||||||
|
quirks_mode,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(emilio): Implement better optimizations for compound selectors and
|
||||||
|
// such.
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
|
||||||
// Slow path for a given selector query.
|
// Slow path for a given selector query.
|
||||||
fn query_selector_slow<E, Q>(
|
fn query_selector_slow<E, Q>(
|
||||||
root: E::ConcreteNode,
|
root: E::ConcreteNode,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue