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,
|
||||
"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,
|
||||
"comma" => ListSeparator::Comma,
|
||||
"space" => ListSeparator::Space,
|
||||
@ -190,7 +190,7 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
|
||||
2,
|
||||
"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" => {
|
||||
if list1.is_empty() || (list1.len() == 1 && sep1 == ListSeparator::Space) {
|
||||
sep2
|
||||
@ -227,7 +227,7 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
|
||||
3,
|
||||
"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,
|
||||
_ => Brackets::Bracketed,
|
||||
},
|
||||
|
@ -28,7 +28,7 @@ fn feature_exists(
|
||||
) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
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
|
||||
// `!global` is used.
|
||||
"global-variable-shadowing" => Value::True,
|
||||
@ -207,7 +207,7 @@ fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) ->
|
||||
span: args.span(),
|
||||
}) {
|
||||
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()),
|
||||
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 {
|
||||
fn into(self) -> Identifier {
|
||||
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)))
|
||||
}
|
||||
|
||||
pub fn resolve(&self) -> String {
|
||||
pub fn resolve(self) -> String {
|
||||
STRINGS.with(|interner| interner.borrow().resolve(&self.0).to_string())
|
||||
}
|
||||
|
||||
pub fn is_empty(self) -> bool {
|
||||
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 {
|
||||
|
@ -252,7 +252,7 @@ impl Value {
|
||||
|
||||
pub fn is_special_function(&self) -> bool {
|
||||
match self {
|
||||
Self::Ident(s, QuoteKind::None) => is_special_function(&s.resolve()),
|
||||
Self::Ident(s, QuoteKind::None) => is_special_function(s.resolve_ref()),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ impl Value {
|
||||
Self::UnaryOp(..) | Self::Paren(..) => self.eval(span)?.node.add(other, span)?,
|
||||
Self::Ident(text, quotes) => match other {
|
||||
Self::Ident(text2, ..) => Self::Ident(
|
||||
InternedString::get_or_intern(text.resolve() + &text2.resolve()),
|
||||
InternedString::get_or_intern(text.resolve() + text2.resolve_ref()),
|
||||
quotes,
|
||||
),
|
||||
_ => Value::Ident(
|
||||
|
Loading…
x
Reference in New Issue
Block a user