mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
style: Allow disabling invalidation-based querySelector from C++
Rust compile times are hard. MozReview-Commit-ID: 9Xhtf7f3Vzv Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
afb09536f9
commit
f32f09656b
2 changed files with 32 additions and 2 deletions
|
@ -512,11 +512,21 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
/// Whether the invalidation machinery should be used for this query.
|
||||
#[derive(PartialEq)]
|
||||
pub enum MayUseInvalidation {
|
||||
/// We may use it if we deem it useful.
|
||||
Yes,
|
||||
/// Don't use it.
|
||||
No,
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#dom-parentnode-queryselector>
|
||||
pub fn query_selector<E, Q>(
|
||||
root: E::ConcreteNode,
|
||||
selector_list: &SelectorList<E::Impl>,
|
||||
results: &mut Q::Output,
|
||||
may_use_invalidation: MayUseInvalidation,
|
||||
)
|
||||
where
|
||||
E: TElement,
|
||||
|
@ -561,6 +571,7 @@ where
|
|||
// A selector with a combinator needs to have a length of at least 3: A
|
||||
// simple selector, a combinator, and another simple selector.
|
||||
let invalidation_may_be_useful =
|
||||
may_use_invalidation == MayUseInvalidation::Yes &&
|
||||
selector_list.0.iter().any(|s| s.len() > 2);
|
||||
|
||||
if root_element.is_some() || !invalidation_may_be_useful {
|
||||
|
|
|
@ -1693,17 +1693,27 @@ pub unsafe extern "C" fn Servo_SelectorList_Matches(
|
|||
pub unsafe extern "C" fn Servo_SelectorList_QueryFirst(
|
||||
node: RawGeckoNodeBorrowed,
|
||||
selectors: RawServoSelectorListBorrowed,
|
||||
may_use_invalidation: bool,
|
||||
) -> *const structs::RawGeckoElement {
|
||||
use std::borrow::Borrow;
|
||||
use style::dom_apis::{self, QueryFirst};
|
||||
use style::dom_apis::{self, MayUseInvalidation, QueryFirst};
|
||||
|
||||
let node = GeckoNode(node);
|
||||
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
||||
let mut result = None;
|
||||
|
||||
let may_use_invalidation =
|
||||
if may_use_invalidation {
|
||||
MayUseInvalidation::Yes
|
||||
} else {
|
||||
MayUseInvalidation::No
|
||||
};
|
||||
|
||||
dom_apis::query_selector::<GeckoElement, QueryFirst>(
|
||||
node,
|
||||
&selectors,
|
||||
&mut result,
|
||||
may_use_invalidation,
|
||||
);
|
||||
|
||||
result.map_or(ptr::null(), |e| e.0)
|
||||
|
@ -1714,19 +1724,28 @@ pub unsafe extern "C" fn Servo_SelectorList_QueryAll(
|
|||
node: RawGeckoNodeBorrowed,
|
||||
selectors: RawServoSelectorListBorrowed,
|
||||
content_list: *mut structs::nsSimpleContentList,
|
||||
may_use_invalidation: bool,
|
||||
) {
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Borrow;
|
||||
use style::dom_apis::{self, QueryAll};
|
||||
use style::dom_apis::{self, MayUseInvalidation, QueryAll};
|
||||
|
||||
let node = GeckoNode(node);
|
||||
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
||||
let mut result = SmallVec::new();
|
||||
|
||||
let may_use_invalidation =
|
||||
if may_use_invalidation {
|
||||
MayUseInvalidation::Yes
|
||||
} else {
|
||||
MayUseInvalidation::No
|
||||
};
|
||||
|
||||
dom_apis::query_selector::<GeckoElement, QueryAll>(
|
||||
node,
|
||||
&selectors,
|
||||
&mut result,
|
||||
may_use_invalidation,
|
||||
);
|
||||
|
||||
if !result.is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue