avoid unnecessary allocations when converting String
to Identifier
This commit is contained in:
parent
558b49af6d
commit
3a5526ab26
@ -127,7 +127,7 @@ fn mixin_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value
|
|||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
match parser.arg(&mut args, 0, "name")? {
|
match parser.arg(&mut args, 0, "name")? {
|
||||||
Value::String(s, _) => Ok(Value::bool(
|
Value::String(s, _) => Ok(Value::bool(
|
||||||
parser.scopes.last().mixin_exists(&s, parser.global_scope),
|
parser.scopes.last().mixin_exists(s, parser.global_scope),
|
||||||
)),
|
)),
|
||||||
v => Err((
|
v => Err((
|
||||||
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
||||||
@ -141,7 +141,7 @@ fn function_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Va
|
|||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
match parser.arg(&mut args, 0, "name")? {
|
match parser.arg(&mut args, 0, "name")? {
|
||||||
Value::String(s, _) => Ok(Value::bool(
|
Value::String(s, _) => Ok(Value::bool(
|
||||||
parser.scopes.last().fn_exists(&s, parser.global_scope),
|
parser.scopes.last().fn_exists(s, parser.global_scope),
|
||||||
)),
|
)),
|
||||||
v => Err((
|
v => Err((
|
||||||
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
||||||
|
@ -115,7 +115,11 @@ pub(crate) struct Identifier(String);
|
|||||||
|
|
||||||
impl From<String> for Identifier {
|
impl From<String> for Identifier {
|
||||||
fn from(s: String) -> Identifier {
|
fn from(s: String) -> Identifier {
|
||||||
Identifier(s.replace('_', "-"))
|
if s.contains('_') {
|
||||||
|
Identifier(s.replace('_', "-"))
|
||||||
|
} else {
|
||||||
|
Identifier(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ impl<'a> Parser<'a> {
|
|||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
CallArg::Positional(args.len())
|
CallArg::Positional(args.len())
|
||||||
} else {
|
} else {
|
||||||
CallArg::Named(name.into())
|
CallArg::Named(mem::take(&mut name).into())
|
||||||
},
|
},
|
||||||
self.parse_value_from_vec(val),
|
self.parse_value_from_vec(val),
|
||||||
);
|
);
|
||||||
@ -261,7 +261,7 @@ impl<'a> Parser<'a> {
|
|||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
CallArg::Positional(args.len())
|
CallArg::Positional(args.len())
|
||||||
} else {
|
} else {
|
||||||
CallArg::Named(name.as_str().into())
|
CallArg::Named(mem::take(&mut name).into())
|
||||||
},
|
},
|
||||||
self.parse_value_from_vec(mem::take(&mut val)),
|
self.parse_value_from_vec(mem::take(&mut val)),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user