avoid cloning selector to determine visibility
This commit is contained in:
parent
86a1ffec42
commit
3ced8feed5
@ -115,33 +115,31 @@ impl ListSeparator {
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord, Copy)]
|
||||
pub(crate) struct Identifier(InternedString);
|
||||
|
||||
impl Identifier {
|
||||
fn from_str(s: &str) -> Self {
|
||||
if s.contains('_') {
|
||||
Identifier(InternedString::get_or_intern(s.replace('_', "-")))
|
||||
} else {
|
||||
Identifier(InternedString::get_or_intern(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Identifier {
|
||||
fn from(s: String) -> Identifier {
|
||||
Identifier(InternedString::get_or_intern(if s.contains('_') {
|
||||
s.replace('_', "-")
|
||||
} else {
|
||||
s
|
||||
}))
|
||||
Self::from_str(&s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&String> for Identifier {
|
||||
fn from(s: &String) -> Identifier {
|
||||
if s.contains('_') {
|
||||
Identifier(InternedString::get_or_intern(s.replace('_', "-")))
|
||||
} else {
|
||||
Identifier(InternedString::get_or_intern(s))
|
||||
}
|
||||
Self::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Identifier {
|
||||
fn from(s: &str) -> Identifier {
|
||||
if s.contains('_') {
|
||||
Identifier(InternedString::get_or_intern(s.replace('_', "-")))
|
||||
} else {
|
||||
Identifier(InternedString::get_or_intern(s))
|
||||
}
|
||||
Self::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -672,13 +672,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
if !self
|
||||
.super_selectors
|
||||
.last()
|
||||
.clone()
|
||||
.into_selector()
|
||||
.is_empty()
|
||||
{
|
||||
if !self.super_selectors.last().as_selector_list().is_empty() {
|
||||
body = vec![Stmt::RuleSet {
|
||||
selector: self.super_selectors.last().clone(),
|
||||
body,
|
||||
@ -719,13 +713,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
if !self
|
||||
.super_selectors
|
||||
.last()
|
||||
.clone()
|
||||
.into_selector()
|
||||
.is_empty()
|
||||
{
|
||||
if !self.super_selectors.last().as_selector_list().is_empty() {
|
||||
body = vec![Stmt::RuleSet {
|
||||
selector: self.super_selectors.last().clone(),
|
||||
body,
|
||||
@ -860,14 +848,14 @@ impl<'a, 'b> Parser<'a, 'b> {
|
||||
}
|
||||
|
||||
let compound = match complex.components.first() {
|
||||
Some(ComplexSelectorComponent::Compound(c)) => c.clone(),
|
||||
Some(ComplexSelectorComponent::Compound(c)) => c,
|
||||
Some(..) | None => todo!(),
|
||||
};
|
||||
if compound.components.len() != 1 {
|
||||
return Err((
|
||||
format!(
|
||||
"compound selectors may no longer be extended.\nConsider `@extend {}` instead.\nSee http://bit.ly/ExtendCompound for details.\n",
|
||||
compound.components.into_iter().map(|x| x.to_string()).collect::<Vec<String>>().join(", ")
|
||||
compound.components.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(", ")
|
||||
)
|
||||
, self.span_before).into());
|
||||
}
|
||||
@ -907,13 +895,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
if !self
|
||||
.super_selectors
|
||||
.last()
|
||||
.clone()
|
||||
.into_selector()
|
||||
.is_empty()
|
||||
{
|
||||
if !self.super_selectors.last().as_selector_list().is_empty() {
|
||||
body = vec![Stmt::RuleSet {
|
||||
selector: self.super_selectors.last().clone(),
|
||||
body,
|
||||
|
@ -2,6 +2,7 @@ use std::{
|
||||
cell::RefCell,
|
||||
collections::{hash_set::IntoIter, HashSet},
|
||||
hash::{Hash, Hasher},
|
||||
ops::Deref,
|
||||
ptr,
|
||||
rc::Rc,
|
||||
};
|
||||
@ -43,6 +44,10 @@ impl ExtendedSelector {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn as_selector_list(&self) -> impl Deref<Target = SelectorList> + '_ {
|
||||
self.0.borrow()
|
||||
}
|
||||
|
||||
pub fn set_inner(&mut self, selector: SelectorList) {
|
||||
self.0.replace(selector);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user