remove superfluous allocations when resolving idents
This commit is contained in:
parent
0d52a1926e
commit
b15740976c
@ -142,7 +142,7 @@ fn append(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
|
|||||||
2,
|
2,
|
||||||
"separator" = Value::Ident(InternedString::get_or_intern("auto"), QuoteKind::None)
|
"separator" = Value::Ident(InternedString::get_or_intern("auto"), QuoteKind::None)
|
||||||
) {
|
) {
|
||||||
Value::Ident(s, ..) => match s.resolve().as_str() {
|
Value::Ident(s, ..) => match s.resolve_ref() {
|
||||||
"auto" => sep,
|
"auto" => sep,
|
||||||
"comma" => ListSeparator::Comma,
|
"comma" => ListSeparator::Comma,
|
||||||
"space" => ListSeparator::Space,
|
"space" => ListSeparator::Space,
|
||||||
@ -190,7 +190,7 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
|
|||||||
2,
|
2,
|
||||||
"separator" = Value::Ident(InternedString::get_or_intern("auto"), QuoteKind::None)
|
"separator" = Value::Ident(InternedString::get_or_intern("auto"), QuoteKind::None)
|
||||||
) {
|
) {
|
||||||
Value::Ident(s, ..) => match s.resolve().as_str() {
|
Value::Ident(s, ..) => match s.resolve_ref() {
|
||||||
"auto" => {
|
"auto" => {
|
||||||
if list1.is_empty() || (list1.len() == 1 && sep1 == ListSeparator::Space) {
|
if list1.is_empty() || (list1.len() == 1 && sep1 == ListSeparator::Space) {
|
||||||
sep2
|
sep2
|
||||||
@ -227,7 +227,7 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
|
|||||||
3,
|
3,
|
||||||
"bracketed" = Value::Ident(InternedString::get_or_intern("auto"), QuoteKind::None)
|
"bracketed" = Value::Ident(InternedString::get_or_intern("auto"), QuoteKind::None)
|
||||||
) {
|
) {
|
||||||
Value::Ident(s, ..) => match s.resolve().as_str() {
|
Value::Ident(s, ..) => match s.resolve_ref() {
|
||||||
"auto" => brackets,
|
"auto" => brackets,
|
||||||
_ => Brackets::Bracketed,
|
_ => Brackets::Bracketed,
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,7 @@ fn feature_exists(
|
|||||||
) -> SassResult<Value> {
|
) -> SassResult<Value> {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "feature") {
|
match arg!(args, scope, super_selector, 0, "feature") {
|
||||||
Value::Ident(s, _) => Ok(match s.resolve().as_str() {
|
Value::Ident(s, _) => Ok(match s.resolve_ref() {
|
||||||
// A local variable will shadow a global variable unless
|
// A local variable will shadow a global variable unless
|
||||||
// `!global` is used.
|
// `!global` is used.
|
||||||
"global-variable-shadowing" => Value::True,
|
"global-variable-shadowing" => Value::True,
|
||||||
@ -207,7 +207,7 @@ fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) ->
|
|||||||
span: args.span(),
|
span: args.span(),
|
||||||
}) {
|
}) {
|
||||||
Ok(f) => SassFunction::UserDefined(Box::new(f), name.into()),
|
Ok(f) => SassFunction::UserDefined(Box::new(f), name.into()),
|
||||||
Err(..) => match GLOBAL_FUNCTIONS.get(&name.resolve().as_str()) {
|
Err(..) => match GLOBAL_FUNCTIONS.get(&name.resolve_ref()) {
|
||||||
Some(f) => SassFunction::Builtin(f.clone(), name.into()),
|
Some(f) => SassFunction::Builtin(f.clone(), name.into()),
|
||||||
None => return Err((format!("Function not found: {}", name), args.span()).into()),
|
None => return Err((format!("Function not found: {}", name), args.span()).into()),
|
||||||
},
|
},
|
||||||
|
@ -127,7 +127,7 @@ pub(crate) struct Identifier(InternedString);
|
|||||||
impl Into<Identifier> for InternedString {
|
impl Into<Identifier> for InternedString {
|
||||||
fn into(self) -> Identifier {
|
fn into(self) -> Identifier {
|
||||||
Identifier(InternedString::get_or_intern(
|
Identifier(InternedString::get_or_intern(
|
||||||
self.resolve().replace('_', "-"),
|
self.resolve_ref().replace('_', "-"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,13 +39,19 @@ impl InternedString {
|
|||||||
Self(STRINGS.with(|interner| interner.borrow_mut().get_or_intern(s)))
|
Self(STRINGS.with(|interner| interner.borrow_mut().get_or_intern(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve(&self) -> String {
|
pub fn resolve(self) -> String {
|
||||||
STRINGS.with(|interner| interner.borrow().resolve(&self.0).to_string())
|
STRINGS.with(|interner| interner.borrow().resolve(&self.0).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(self) -> bool {
|
pub fn is_empty(self) -> bool {
|
||||||
EMPTY_STRING.with(|f| self == **f)
|
EMPTY_STRING.with(|f| self == **f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolve_ref<'a>(self) -> &'a str {
|
||||||
|
unsafe {
|
||||||
|
STRINGS.with(|interner| &(*(interner.as_ptr()).as_ref().unwrap().resolve(&self.0)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for InternedString {
|
impl Display for InternedString {
|
||||||
|
@ -252,7 +252,7 @@ impl Value {
|
|||||||
|
|
||||||
pub fn is_special_function(&self) -> bool {
|
pub fn is_special_function(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Ident(s, QuoteKind::None) => is_special_function(&s.resolve()),
|
Self::Ident(s, QuoteKind::None) => is_special_function(s.resolve_ref()),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ impl Value {
|
|||||||
Self::UnaryOp(..) | Self::Paren(..) => self.eval(span)?.node.add(other, span)?,
|
Self::UnaryOp(..) | Self::Paren(..) => self.eval(span)?.node.add(other, span)?,
|
||||||
Self::Ident(text, quotes) => match other {
|
Self::Ident(text, quotes) => match other {
|
||||||
Self::Ident(text2, ..) => Self::Ident(
|
Self::Ident(text2, ..) => Self::Ident(
|
||||||
InternedString::get_or_intern(text.resolve() + &text2.resolve()),
|
InternedString::get_or_intern(text.resolve() + text2.resolve_ref()),
|
||||||
quotes,
|
quotes,
|
||||||
),
|
),
|
||||||
_ => Value::Ident(
|
_ => Value::Ident(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user