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.
This commit is contained in:
parent
11170ac5b3
commit
05b6b539ad
16
src/scope.rs
16
src/scope.rs
@ -10,7 +10,7 @@ use crate::{
|
||||
value::Value,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Scope {
|
||||
vars: HashMap<Identifier, Spanned<Value>>,
|
||||
mixins: HashMap<Identifier, Mixin>,
|
||||
@ -79,7 +79,7 @@ impl Scope {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Scopes(Vec<Scope>);
|
||||
|
||||
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<Mixin> {
|
||||
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<Function> {
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user