From 05b6b539ad1a60a9e63cebafa7caa0f20613e118 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 8 Jul 2020 20:26:54 -0400 Subject: [PATCH] avoid creating unnecessary errors previously, when attempting to locate a mixin/fn/variable, we would check if it existing simply by calling `get_{mixin,fn,var}`. this caused *large* performance regressions in bootstrap, where almost 15% of the execution time was spent in these functions. the cause for this was that `get_*` both allocates a new String and boxes the error. --- src/scope.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/scope.rs b/src/scope.rs index 552d6a4..c4f5aef 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -10,7 +10,7 @@ use crate::{ value::Value, }; -#[derive(Debug, Clone, Default)] +#[derive(Debug, Default)] pub(crate) struct Scope { vars: HashMap>, mixins: HashMap, @@ -79,7 +79,7 @@ impl Scope { } } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Default)] pub(crate) struct Scopes(Vec); impl Scopes { @@ -148,8 +148,8 @@ impl Scopes { global_scope: &'a Scope, ) -> SassResult<&Value> { for scope in self.0.iter().rev() { - if let Ok(v) = scope.get_var(name) { - return Ok(v); + if scope.var_exists(&name.node) { + return scope.get_var(name); } } global_scope.get_var(name) @@ -184,8 +184,8 @@ impl Scopes { global_scope: &'a Scope, ) -> SassResult { for scope in self.0.iter().rev() { - if let Ok(v) = scope.get_mixin(name) { - return Ok(v); + if scope.mixin_exists(&name.node) { + return scope.get_mixin(name); } } global_scope.get_mixin(name) @@ -220,8 +220,8 @@ impl Scopes { global_scope: &'a Scope, ) -> SassResult { for scope in self.0.iter().rev() { - if let Ok(v) = scope.get_fn(name) { - return Ok(v); + if scope.fn_exists(&name.node) { + return scope.get_fn(name); } } global_scope.get_fn(name)