style: Make Invalidation work in terms of a dependency, not a selector.

That way we can look at the parent dependency as described in the previous
patch. An alternative would be to add a:

    parent_dependency: Option<&'a Dependency>

on construction to `Invalidation`, but this way seems slightly better to avoid
growing the struct. It's not even one more indirection because the selector is
contained directly in the Dependency struct.

Differential Revision: https://phabricator.services.mozilla.com/D71422
This commit is contained in:
Emilio Cobos Álvarez 2020-04-23 19:20:10 +00:00
parent c1bc588c93
commit 4b5de772c6
5 changed files with 315 additions and 202 deletions

View file

@ -85,8 +85,8 @@ pub fn check_dependency<E, W>(
dependency: &Dependency,
element: &E,
wrapper: &W,
context: &mut MatchingContext<'_, SelectorImpl>,
)
mut context: &mut MatchingContext<'_, E::Impl>,
) -> bool
where
E: TElement,
W: selectors::Element<Impl = E::Impl>,
@ -166,6 +166,14 @@ where
true
}
fn check_outer_dependency(&mut self, dependency: &Dependency, element: E) -> bool {
// We cannot assert about `element` having a snapshot here (in fact it
// most likely won't), because it may be an arbitrary descendant or
// later-sibling of the element we started invalidating with.
let wrapper = ElementWrapper::new(element, &*self.shared_context.snapshot_map);
check_dependency(dependency, &element, &wrapper, &mut self.matching_context)
}
fn matching_context(&mut self) -> &mut MatchingContext<'a, E::Impl> {
&mut self.matching_context
}
@ -447,7 +455,7 @@ where
/// Check whether a dependency should be taken into account.
#[inline]
fn check_dependency(&mut self, dependency: &Dependency) -> bool {
check_dependency(&self.element, &self.wrapper, &mut self.matching_context)
check_dependency(dependency, &self.element, &self.wrapper, &mut self.matching_context)
}
fn scan_dependency(&mut self, dependency: &'selectors Dependency) {
@ -484,9 +492,8 @@ where
debug_assert_ne!(dependency.selector_offset, dependency.selector.len());
let invalidation = Invalidation::new(
&dependency.selector,
&dependency,
self.matching_context.current_host.clone(),
dependency.selector.len() - dependency.selector_offset + 1,
);
match invalidation_kind {