diff --git a/src/builtin/list.rs b/src/builtin/list.rs index bcca5c8..e9f4976 100644 --- a/src/builtin/list.rs +++ b/src/builtin/list.rs @@ -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, }, diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index 29c9969..6ca7fc1 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -28,7 +28,7 @@ fn feature_exists( ) -> SassResult { 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()), }, diff --git a/src/common.rs b/src/common.rs index dcecdf7..3b24976 100644 --- a/src/common.rs +++ b/src/common.rs @@ -127,7 +127,7 @@ pub(crate) struct Identifier(InternedString); impl Into for InternedString { fn into(self) -> Identifier { Identifier(InternedString::get_or_intern( - self.resolve().replace('_', "-"), + self.resolve_ref().replace('_', "-"), )) } } diff --git a/src/interner.rs b/src/interner.rs index d0d7ed1..32de6e7 100644 --- a/src/interner.rs +++ b/src/interner.rs @@ -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 { diff --git a/src/value/mod.rs b/src/value/mod.rs index f7ff32f..d98aca4 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -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, } } diff --git a/src/value/ops.rs b/src/value/ops.rs index 201bfcc..3461f2d 100644 --- a/src/value/ops.rs +++ b/src/value/ops.rs @@ -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(