convert immutable Strings to Box<str> in Pseudo
This commit is contained in:
parent
0483f7f057
commit
c7608fce4e
@ -603,7 +603,7 @@ fn first_if_root(queue: &mut VecDeque<ComplexSelectorComponent>) -> Option<Compo
|
||||
fn has_root(compound: &CompoundSelector) -> bool {
|
||||
compound.components.iter().any(|simple| {
|
||||
if let SimpleSelector::Pseudo(pseudo) = simple {
|
||||
pseudo.is_class && pseudo.normalized_name == "root"
|
||||
pseudo.is_class && &*pseudo.normalized_name == "root"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -597,7 +597,7 @@ impl Extender {
|
||||
// writing. We can keep them if either the original selector had a complex
|
||||
// selector, or the result of extending has only complex selectors, because
|
||||
// either way we aren't breaking anything that isn't already broken.
|
||||
let mut complexes = if pseudo.normalized_name == "not"
|
||||
let mut complexes = if &*pseudo.normalized_name == "not"
|
||||
&& !pseudo
|
||||
.selector
|
||||
.clone()
|
||||
@ -643,7 +643,7 @@ impl Extender {
|
||||
return vec![complex];
|
||||
}
|
||||
|
||||
match pseudo.normalized_name.as_str() {
|
||||
match &*pseudo.normalized_name {
|
||||
"not" => {
|
||||
// In theory, if there's a `:not` nested within another `:not`, the
|
||||
// inner `:not`'s contents should be unified with the return value.
|
||||
@ -651,7 +651,7 @@ impl Extender {
|
||||
// become `.foo:not(.bar)`. However, this is a narrow edge case and
|
||||
// supporting it properly would make this code and the code calling it
|
||||
// a lot more complicated, so it's not supported for now.
|
||||
if inner_pseudo.normalized_name == "matches" {
|
||||
if &*inner_pseudo.normalized_name == "matches" {
|
||||
inner_pseudo.selector.clone().unwrap().components
|
||||
} else {
|
||||
Vec::new()
|
||||
@ -683,7 +683,8 @@ impl Extender {
|
||||
// Older browsers support `:not`, but only with a single complex selector.
|
||||
// In order to support those browsers, we break up the contents of a `:not`
|
||||
// unless it originally contained a selector list.
|
||||
if pseudo.normalized_name == "not" && pseudo.selector.clone().unwrap().components.len() == 1
|
||||
if &*pseudo.normalized_name == "not"
|
||||
&& pseudo.selector.clone().unwrap().components.len() == 1
|
||||
{
|
||||
let result = complexes
|
||||
.into_iter()
|
||||
|
@ -296,7 +296,7 @@ impl<'a, 'b> SelectorParser<'a, 'b> {
|
||||
_ => {
|
||||
return Ok(SimpleSelector::Pseudo(Pseudo {
|
||||
// todo: we can store the reference to this
|
||||
normalized_name: unvendor(&name.node).to_string(),
|
||||
normalized_name: unvendor(&name.node).to_string().into_boxed_str(),
|
||||
is_class: !element && !is_fake_pseudo_element(&name),
|
||||
name: name.node,
|
||||
selector: None,
|
||||
@ -311,7 +311,7 @@ impl<'a, 'b> SelectorParser<'a, 'b> {
|
||||
|
||||
let unvendored = unvendor(&name);
|
||||
|
||||
let mut argument: Option<String> = None;
|
||||
let mut argument: Option<Box<str>> = None;
|
||||
let mut selector: Option<SelectorList> = None;
|
||||
|
||||
if element {
|
||||
@ -321,7 +321,7 @@ impl<'a, 'b> SelectorParser<'a, 'b> {
|
||||
self.parser.whitespace();
|
||||
self.expect_closing_paren()?;
|
||||
} else {
|
||||
argument = Some(self.declaration_value()?);
|
||||
argument = Some(self.declaration_value()?.into_boxed_str());
|
||||
}
|
||||
} else if SELECTOR_PSEUDO_CLASSES.contains(&unvendored) {
|
||||
selector = Some(self.parse_selector_list()?);
|
||||
@ -342,13 +342,18 @@ impl<'a, 'b> SelectorParser<'a, 'b> {
|
||||
_ => {}
|
||||
}
|
||||
self.expect_closing_paren()?;
|
||||
argument = Some(this_arg);
|
||||
argument = Some(this_arg.into_boxed_str());
|
||||
} else {
|
||||
argument = Some(self.declaration_value()?.trim_end().to_string());
|
||||
argument = Some(
|
||||
self.declaration_value()?
|
||||
.trim_end()
|
||||
.to_string()
|
||||
.into_boxed_str(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(SimpleSelector::Pseudo(Pseudo {
|
||||
normalized_name: unvendor(&name.node).to_string(),
|
||||
normalized_name: unvendor(&name.node).to_string().into_boxed_str(),
|
||||
is_class: !element && !is_fake_pseudo_element(&name),
|
||||
name: name.node,
|
||||
selector,
|
||||
|
@ -356,7 +356,7 @@ impl SimpleSelector {
|
||||
..
|
||||
}) = their_simple
|
||||
{
|
||||
if SUBSELECTOR_PSEUDOS.contains(&normalized_name.as_str()) {
|
||||
if SUBSELECTOR_PSEUDOS.contains(&&**normalized_name) {
|
||||
return sel.components.iter().all(|complex| {
|
||||
if complex.components.len() != 1 {
|
||||
return false;
|
||||
@ -384,7 +384,7 @@ pub(crate) struct Pseudo {
|
||||
pub name: String,
|
||||
|
||||
/// Like `name`, but without any vendor prefixes.
|
||||
pub normalized_name: String,
|
||||
pub normalized_name: Box<str>,
|
||||
|
||||
/// Whether this is a pseudo-class selector.
|
||||
///
|
||||
@ -404,7 +404,7 @@ pub(crate) struct Pseudo {
|
||||
///
|
||||
/// This is `None` if there's no argument. If `argument` and `selector` are
|
||||
/// both non-`None`, the selector follows the argument.
|
||||
pub argument: Option<String>,
|
||||
pub argument: Option<Box<str>>,
|
||||
|
||||
/// The selector argument passed to this selector.
|
||||
///
|
||||
@ -488,7 +488,7 @@ impl Pseudo {
|
||||
parents: Option<Vec<ComplexSelectorComponent>>,
|
||||
) -> bool {
|
||||
debug_assert!(self.selector.is_some());
|
||||
match self.normalized_name.as_str() {
|
||||
match &*self.normalized_name {
|
||||
"matches" | "any" => {
|
||||
let pseudos = selector_pseudos_named(compound.clone(), &self.name, true);
|
||||
pseudos.iter().any(move |pseudo2| {
|
||||
|
@ -78,7 +78,6 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
||||
let mut times_ten_is_postive = true;
|
||||
#[allow(clippy::never_loop)]
|
||||
loop {
|
||||
// TODO: https://github.com/rust-lang/rust/issues/54883
|
||||
if let Some(Token { kind: 'e', .. }) | Some(Token { kind: 'E', .. }) = toks.peek() {
|
||||
let t = if let Some(tok) = toks.peek_forward(1) {
|
||||
*tok
|
||||
|
Loading…
x
Reference in New Issue
Block a user