Skip to content

Commit 7d422d8

Browse files
committed
Bump selectors and cssparser to their current stable versions and adjust our usage as necessary.
1 parent e0d4ea7 commit 7d422d8

File tree

6 files changed

+58
-63
lines changed

6 files changed

+58
-63
lines changed

Cargo.lock

Lines changed: 13 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scraper/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ repository = "https://github.com/causal-agent/scraper"
1313
readme = "README.md"
1414

1515
[dependencies]
16-
cssparser = "0.31.0"
16+
ahash = "0.8.0"
17+
cssparser = "0.34.0"
1718
ego-tree = "0.9.0"
18-
html5ever = "0.27"
19-
selectors = "0.25.0"
20-
tendril = "0.4.3"
21-
ahash = "0.8"
19+
html5ever = "0.27.0"
2220
indexmap = { version = "2.6.0", optional = true }
21+
precomputed-hash = "0.1.1"
22+
selectors = "0.26.0"
23+
tendril = "0.4.3"
2324

2425
[dependencies.getopts]
2526
version = "0.2.21"

scraper/src/element_ref/element.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use html5ever::Namespace;
22
use selectors::{
33
attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint},
4+
bloom::BloomFilter,
45
matching, Element, OpaqueElement,
56
};
67

@@ -122,6 +123,10 @@ impl<'a> Element for ElementRef<'a> {
122123
self.value().has_class(&name.0, case_sensitivity)
123124
}
124125

126+
fn has_custom_state(&self, _name: &CssLocalName) -> bool {
127+
false
128+
}
129+
125130
fn is_empty(&self) -> bool {
126131
!self
127132
.children()
@@ -134,6 +139,11 @@ impl<'a> Element for ElementRef<'a> {
134139
}
135140

136141
fn apply_selector_flags(&self, _flags: matching::ElementSelectorFlags) {}
142+
143+
fn add_element_unique_hashes(&self, _filter: &mut BloomFilter) -> bool {
144+
// FIXME: Do we want to add `self.node.id()` here?
145+
false
146+
}
137147
}
138148

139149
#[cfg(test)]

scraper/src/element_ref/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ops::Deref;
77
use ego_tree::iter::{Edge, Traverse};
88
use ego_tree::NodeRef;
99
use html5ever::serialize::{serialize, SerializeOpts, TraversalScope};
10-
use selectors::NthIndexCache;
10+
use selectors::matching::SelectorCaches;
1111

1212
use crate::node::Element;
1313
use crate::{Node, Selector};
@@ -49,7 +49,7 @@ impl<'a> ElementRef<'a> {
4949
scope: *self,
5050
inner,
5151
selector,
52-
nth_index_cache: NthIndexCache::default(),
52+
caches: Default::default(),
5353
}
5454
}
5555

@@ -135,7 +135,7 @@ pub struct Select<'a, 'b> {
135135
scope: ElementRef<'a>,
136136
inner: Traverse<'a, Node>,
137137
selector: &'b Selector,
138-
nth_index_cache: NthIndexCache,
138+
caches: SelectorCaches,
139139
}
140140

141141
impl Debug for Select<'_, '_> {
@@ -144,7 +144,7 @@ impl Debug for Select<'_, '_> {
144144
.field("scope", &self.scope)
145145
.field("inner", &self.inner)
146146
.field("selector", &self.selector)
147-
.field("nth_index_cache", &"..")
147+
.field("caches", &"..")
148148
.finish()
149149
}
150150
}
@@ -155,7 +155,7 @@ impl Clone for Select<'_, '_> {
155155
scope: self.scope,
156156
inner: self.inner.clone(),
157157
selector: self.selector,
158-
nth_index_cache: NthIndexCache::default(),
158+
caches: Default::default(),
159159
}
160160
}
161161
}
@@ -170,7 +170,7 @@ impl<'a, 'b> Iterator for Select<'a, 'b> {
170170
if self.selector.matches_with_scope_and_cache(
171171
&element,
172172
Some(self.scope),
173-
&mut self.nth_index_cache,
173+
&mut self.caches,
174174
) {
175175
return Some(element);
176176
}

scraper/src/html/mod.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ego_tree::Tree;
1010
use html5ever::serialize::SerializeOpts;
1111
use html5ever::tree_builder::QuirksMode;
1212
use html5ever::{driver, serialize, QualName};
13-
use selectors::NthIndexCache;
13+
use selectors::matching::SelectorCaches;
1414
use tendril::TendrilSink;
1515

1616
use crate::selector::Selector;
@@ -95,7 +95,7 @@ impl Html {
9595
Select {
9696
inner: self.tree.nodes(),
9797
selector,
98-
nth_index_cache: NthIndexCache::default(),
98+
caches: Default::default(),
9999
}
100100
}
101101

@@ -127,15 +127,15 @@ impl Html {
127127
pub struct Select<'a, 'b> {
128128
inner: Nodes<'a, Node>,
129129
selector: &'b Selector,
130-
nth_index_cache: NthIndexCache,
130+
caches: SelectorCaches,
131131
}
132132

133133
impl fmt::Debug for Select<'_, '_> {
134134
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
135135
fmt.debug_struct("Select")
136136
.field("inner", &self.inner)
137137
.field("selector", &self.selector)
138-
.field("nth_index_cache", &"..")
138+
.field("caches", &"..")
139139
.finish()
140140
}
141141
}
@@ -145,7 +145,7 @@ impl Clone for Select<'_, '_> {
145145
Self {
146146
inner: self.inner.clone(),
147147
selector: self.selector,
148-
nth_index_cache: NthIndexCache::default(),
148+
caches: Default::default(),
149149
}
150150
}
151151
}
@@ -157,11 +157,9 @@ impl<'a, 'b> Iterator for Select<'a, 'b> {
157157
for node in self.inner.by_ref() {
158158
if let Some(element) = ElementRef::wrap(node) {
159159
if element.parent().is_some()
160-
&& self.selector.matches_with_scope_and_cache(
161-
&element,
162-
None,
163-
&mut self.nth_index_cache,
164-
)
160+
&& self
161+
.selector
162+
.matches_with_scope_and_cache(&element, None, &mut self.caches)
165163
{
166164
return Some(element);
167165
}
@@ -182,11 +180,9 @@ impl<'a, 'b> DoubleEndedIterator for Select<'a, 'b> {
182180
for node in self.inner.by_ref().rev() {
183181
if let Some(element) = ElementRef::wrap(node) {
184182
if element.parent().is_some()
185-
&& self.selector.matches_with_scope_and_cache(
186-
&element,
187-
None,
188-
&mut self.nth_index_cache,
189-
)
183+
&& self
184+
.selector
185+
.matches_with_scope_and_cache(&element, None, &mut self.caches)
190186
{
191187
return Some(element);
192188
}

scraper/src/selector.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::fmt;
55

66
pub use cssparser::ToCss;
77
use html5ever::{LocalName, Namespace};
8+
use precomputed_hash::PrecomputedHash;
89
use selectors::{
910
matching,
1011
parser::{self, ParseRelative, SelectorList, SelectorParseErrorKind},
11-
NthIndexCache,
1212
};
1313

1414
use crate::error::SelectorErrorKind;
@@ -43,7 +43,7 @@ impl Selector {
4343
/// The optional `scope` argument is used to specify which element has `:scope` pseudo-class.
4444
/// When it is `None`, `:scope` will match the root element.
4545
pub fn matches_with_scope(&self, element: &ElementRef, scope: Option<ElementRef>) -> bool {
46-
self.matches_with_scope_and_cache(element, scope, &mut NthIndexCache::default())
46+
self.matches_with_scope_and_cache(element, scope, &mut Default::default())
4747
}
4848

4949
// The `nth_index_cache` must not be used after `self` is dropped
@@ -53,19 +53,19 @@ impl Selector {
5353
&self,
5454
element: &ElementRef,
5555
scope: Option<ElementRef>,
56-
nth_index_cache: &mut NthIndexCache,
56+
caches: &mut matching::SelectorCaches,
5757
) -> bool {
5858
let mut context = matching::MatchingContext::new(
5959
matching::MatchingMode::Normal,
6060
None,
61-
nth_index_cache,
61+
caches,
6262
matching::QuirksMode::NoQuirks,
6363
matching::NeedsSelectorFlags::No,
64-
matching::IgnoreNthChildForInvalidation::No,
64+
matching::MatchingForInvalidation::No,
6565
);
6666
context.scope_element = scope.map(|x| selectors::Element::opaque(&x));
6767
self.selectors
68-
.0
68+
.slice()
6969
.iter()
7070
.any(|s| matching::matches_selector(s, 0, None, element, &mut context))
7171
}
@@ -160,6 +160,12 @@ impl ToCss for CssLocalName {
160160
}
161161
}
162162

163+
impl PrecomputedHash for CssLocalName {
164+
fn precomputed_hash(&self) -> u32 {
165+
self.0.precomputed_hash()
166+
}
167+
}
168+
163169
/// Non Tree-Structural Pseudo-Class.
164170
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
165171
pub enum NonTSPseudoClass {}

0 commit comments

Comments
 (0)