avoid allocating unnecessary errors for getting functions
This commit is contained in:
parent
05b6b539ad
commit
ca370eb9b0
@ -188,8 +188,8 @@ fn get_function(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value
|
||||
},
|
||||
parser.global_scope,
|
||||
) {
|
||||
Ok(f) => SassFunction::UserDefined(Box::new(f), name),
|
||||
Err(..) => match GLOBAL_FUNCTIONS.get(name.as_str()) {
|
||||
Some(f) => SassFunction::UserDefined(Box::new(f), name),
|
||||
None => match GLOBAL_FUNCTIONS.get(name.as_str()) {
|
||||
Some(f) => SassFunction::Builtin(f.clone(), name),
|
||||
None => return Err((format!("Function not found: {}", name), args.span()).into()),
|
||||
},
|
||||
|
@ -263,8 +263,8 @@ impl<'a> Parser<'a> {
|
||||
},
|
||||
self.global_scope,
|
||||
) {
|
||||
Ok(f) => f,
|
||||
Err(_) => {
|
||||
Some(f) => f,
|
||||
None => {
|
||||
if let Some(f) = GLOBAL_FUNCTIONS.get(as_ident.as_str()) {
|
||||
return Ok(IntermediateValue::Value(HigherIntermediateValue::Function(
|
||||
SassFunction::Builtin(f.clone(), as_ident),
|
||||
|
13
src/scope.rs
13
src/scope.rs
@ -57,11 +57,8 @@ impl Scope {
|
||||
self.mixins.contains_key(name)
|
||||
}
|
||||
|
||||
fn get_fn(&self, name: Spanned<&Identifier>) -> SassResult<Function> {
|
||||
match self.functions.get(name.node) {
|
||||
Some(v) => Ok(v.clone()),
|
||||
None => Err(("Undefined function.", name.span).into()),
|
||||
}
|
||||
fn get_fn(&self, name: &Identifier) -> Option<Function> {
|
||||
self.functions.get(name).cloned()
|
||||
}
|
||||
|
||||
pub fn insert_fn<T: Into<Identifier>>(&mut self, s: T, v: Function) -> Option<Function> {
|
||||
@ -218,13 +215,13 @@ impl Scopes {
|
||||
&'a self,
|
||||
name: Spanned<&Identifier>,
|
||||
global_scope: &'a Scope,
|
||||
) -> SassResult<Function> {
|
||||
) -> Option<Function> {
|
||||
for scope in self.0.iter().rev() {
|
||||
if scope.fn_exists(&name.node) {
|
||||
return scope.get_fn(name);
|
||||
return scope.get_fn(name.node);
|
||||
}
|
||||
}
|
||||
global_scope.get_fn(name)
|
||||
global_scope.get_fn(name.node)
|
||||
}
|
||||
|
||||
pub fn fn_exists(&self, name: &Identifier, global_scope: &Scope) -> bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user