Skip to content

Commit

Permalink
Remove unnecessary compile time environment clones
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Sep 7, 2024
1 parent 1bb1417 commit 9643c37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 9 additions & 0 deletions core/engine/src/environments/runtime/declarative/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ impl DeclarativeEnvironment {
&self.kind
}

/// Returns whether this environment is a function environment.
pub(crate) fn is_function(&self) -> bool {
if let DeclarativeEnvironmentKind::Function(_) = self.kind() {
true
} else {
false
}
}

/// Gets the binding value from the environment by index.
///
/// # Panics
Expand Down
11 changes: 6 additions & 5 deletions core/engine/src/environments/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl EnvironmentStack {
.filter_map(Environment::as_declarative)
{
env.poison();
if env.compile_env().is_function() {
if env.is_function() {
return;
}
}
Expand Down Expand Up @@ -513,8 +513,8 @@ impl Context {
match self.environment_expect(index) {
Environment::Declarative(env) => {
if env.poisoned() {
let compile = env.compile_env();
if compile.is_function() {
if env.is_function() {
let compile = env.compile_env();
if let Some(b) = compile.get_binding(locator.name()) {
locator.set_environment(b.environment());
locator.binding_index = b.binding_index();
Expand Down Expand Up @@ -578,8 +578,9 @@ impl Context {
match self.environment_expect(index) {
Environment::Declarative(env) => {
if env.poisoned() {
let compile = env.compile_env();
if compile.is_function() && compile.get_binding(locator.name()).is_some() {
if env.is_function()
&& env.compile_env().get_binding(locator.name()).is_some()
{
break;
}
} else if !env.with() {
Expand Down

0 comments on commit 9643c37

Please sign in to comment.