Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Sync changes from mozilla-central. #22111

Merged
merged 32 commits into from Nov 5, 2018
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
26040d1
style: Remove unused style constant.
emilio Oct 24, 2018
a9af61e
style: Don't allow auto in grid line names.
emilio Oct 28, 2018
a3fcfb6
style: Add a fast path for querySelector{,All} when we have classes o…
emilio Oct 29, 2018
62aaf86
style: Ignore border-image-source when overriding document colors.
Oct 29, 2018
badb8f3
style: Support ::before / ::after on ::slotted pseudos.
emilio Oct 29, 2018
edf6e6a
style: Update cbindgen due to breaking change.
emilio Oct 30, 2018
8bc8a0b
style: Interpolate the angle between mis-matched rotate() functions w…
birtles Oct 30, 2018
b00bbb3
style: Add a special list for cbindgen types to avoid generating redu…
BorisChiou Oct 31, 2018
591a478
style: Use alias for StyleAppearance.
BorisChiou Oct 31, 2018
cb2533d
style: Use alias for StyleDisplay and StyleDisplayMode.
BorisChiou Oct 31, 2018
c7027e2
style: Use alias for StyleFillRule.
BorisChiou Oct 31, 2018
b81bbb8
style: Use alias for StylePathCommand.
BorisChiou Oct 31, 2018
33b2514
style: Drop "mozilla" prefix in cbindgen_types in ServoBindings.toml.
BorisChiou Oct 31, 2018
5976956
style: Handle reversed ranges in @font-face descriptors.
heycam Oct 31, 2018
d43c4ce
style: Support unprefixed image-rendering: crisp-edges.
heycam Nov 1, 2018
52c3ba0
style: Fix inconsistent CRISPEDGES constant name.
heycam Nov 1, 2018
a7b5ba1
style: Use references in the shapes code.
emilio Nov 2, 2018
33fed65
style: Don't match document author rules if not needed for revalidation.
emilio Nov 5, 2018
d035d02
style: Don't keep a separate list of ignored-when-colors-disabled lon…
emilio Nov 5, 2018
282edf1
style: Move shorthand IDL order stuff out of animated_properties.
emilio Nov 4, 2018
f159c20
style: Move the keyframes property priority stuff outside of animated…
emilio Nov 4, 2018
778ae7d
style: Move various length animation implementations to its own file.
emilio Nov 4, 2018
707bd84
style: Move various font-related animation code to its own file.
emilio Nov 4, 2018
8b49ef8
style: Remove nscsspropertyid_is_{animatable,transitionable}.
emilio Nov 4, 2018
c88a483
style: Move animation of svg-related bits outside of animated_propert…
emilio Nov 4, 2018
5af6abf
style: Simplify the SVG animation code.
emilio Nov 4, 2018
b7da1ba
style: Implement the env() function with hardcoded zeros for safe-are…
emilio Nov 5, 2018
99f9d84
style: Simplify invalid custom property handling.
emilio Nov 5, 2018
29f5691
Update remaining references to cssparser 0.24.
emilio Nov 5, 2018
8560c8d
Fix tidy issues.
emilio Nov 5, 2018
64e70e2
style: Add the safe area constant names as atoms.
emilio Nov 5, 2018
ac6f921
style: Fix servo build.
emilio Nov 5, 2018
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

style: Add a fast path for querySelector{,All} when we have classes o…

…r tags in the rightmost compound.

Before this patch we were only optimizing the case of a single selector, which
is fine, but not enough to catch ones like .foo .bar or so.

This patch allows us to optimize classes and tags in the rightmost compound,
while keeping the current optimization for #id selectors.

Need to profile this, but code-wise should be ready for review.

Differential Revision: https://phabricator.services.mozilla.com/D9351
  • Loading branch information
emilio committed Nov 5, 2018
commit a3fcfb6435fa3cde019ed4c7c69e604225b45a89
@@ -13,7 +13,7 @@ use invalidation::element::invalidator::{InvalidationProcessor, InvalidationVect
use selectors::{Element, NthIndexCache, SelectorList};
use selectors::attr::CaseSensitivity;
use selectors::matching::{self, MatchingContext, MatchingMode};
use selectors::parser::{Combinator, Component, LocalName};
use selectors::parser::{Combinator, Component, LocalName, SelectorImpl};
use smallvec::SmallVec;
use std::borrow::Borrow;

@@ -333,6 +333,19 @@ fn collect_elements_with_id<E, Q, F>(
}
}

#[inline(always)]
fn local_name_matches<E>(element: E, local_name: &LocalName<E::Impl>) -> bool
where
E: TElement,
{
let LocalName { ref name, ref lower_name } = *local_name;
if element.is_html_element_in_html_document() {
element.local_name() == lower_name.borrow()
} else {
element.local_name() == name.borrow()
}
}

/// Fast paths for querySelector with a single simple selector.
fn query_selector_single_query<E, Q>(
root: E::ConcreteNode,
@@ -357,25 +370,30 @@ where
element.has_class(class, case_sensitivity)
})
},
Component::LocalName(LocalName {
ref name,
ref lower_name,
}) => collect_all_elements::<E, Q, _>(root, results, |element| {
if element.is_html_element_in_html_document() {
element.local_name() == lower_name.borrow()
} else {
element.local_name() == name.borrow()
}
}),
Component::LocalName(ref local_name) => {
collect_all_elements::<E, Q, _>(root, results, |element| {
local_name_matches(element, local_name)
})
},
// TODO(emilio): More fast paths?
_ => return Err(()),
}

Ok(())
}

enum SimpleFilter<'a, Impl: SelectorImpl> {
Class(&'a Atom),
LocalName(&'a LocalName<Impl>),
}

/// Fast paths for a given selector query.
///
/// When there's only one component, we go directly to
/// `query_selector_single_query`, otherwise, we try to optimize by looking just
/// at the subtrees rooted at ids in the selector, and otherwise we try to look
/// up by class name or local name in the rightmost compound.
///
/// FIXME(emilio, nbp): This may very well be a good candidate for code to be
/// replaced by HolyJit :)
fn query_selector_fast<E, Q>(
@@ -410,7 +428,12 @@ where
let mut iter = selector.iter();
let mut combinator: Option<Combinator> = None;

loop {
// We want to optimize some cases where there's no id involved whatsoever,
// like `.foo .bar`, but we don't want to make `#foo .bar` slower because of
// that.
let mut simple_filter = None;

'selector_loop: loop {
debug_assert!(combinator.map_or(true, |c| !c.is_sibling()));

'component_loop: for component in &mut iter {
@@ -469,13 +492,28 @@ where

return Ok(());
},
Component::Class(ref class) => {
if combinator.is_none() {
simple_filter = Some(SimpleFilter::Class(class));
}
},
Component::LocalName(ref local_name) => {
if combinator.is_none() {
// Prefer to look at class rather than local-name if
// both are present.
if let Some(SimpleFilter::Class(..)) = simple_filter {
continue;
}
simple_filter = Some(SimpleFilter::LocalName(local_name));
}
},
_ => {},
}
}

loop {
let next_combinator = match iter.next_sequence() {
None => return Err(()),
None => break 'selector_loop,
Some(c) => c,
};

@@ -492,6 +530,39 @@ where
break;
}
}

// We got here without finding any ID or such that we could handle. Try to
// use one of the simple filters.
let simple_filter = match simple_filter {
Some(f) => f,
None => return Err(()),
};

match simple_filter {
SimpleFilter::Class(ref class) => {
let case_sensitivity = quirks_mode.classes_and_ids_case_sensitivity();
collect_all_elements::<E, Q, _>(root, results, |element| {
element.has_class(class, case_sensitivity) &&
matching::matches_selector_list(
selector_list,
&element,
matching_context,
)
});
}
SimpleFilter::LocalName(ref local_name) => {
collect_all_elements::<E, Q, _>(root, results, |element| {
local_name_matches(element, local_name) &&
matching::matches_selector_list(
selector_list,
&element,
matching_context,
)
});
}
}

Ok(())
}

// Slow path for a given selector query.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.