Browse Source

Remove some environment clones (#3884)

pull/3885/head
raskad 6 months ago committed by GitHub
parent
commit
eb439557ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      core/engine/src/builtins/eval/mod.rs
  2. 2
      core/engine/src/builtins/function/arguments.rs
  3. 17
      core/engine/src/environments/runtime/mod.rs
  4. 4
      core/engine/src/module/source.rs
  5. 2
      core/engine/src/module/synthetic.rs
  6. 2
      core/engine/src/vm/opcode/arguments.rs

2
core/engine/src/builtins/eval/mod.rs

@ -229,7 +229,7 @@ impl Eval {
}
});
let var_environment = context.vm.environments.outer_function_environment();
let var_environment = context.vm.environments.outer_function_environment().clone();
let mut var_env = var_environment.compile_env();
let lex_env = context.vm.environments.current_compile_environment();

2
core/engine/src/builtins/function/arguments.rs

@ -207,7 +207,7 @@ impl MappedArguments {
binding_indices: &[Option<u32>],
arguments_list: &[JsValue],
env: &Gc<DeclarativeEnvironment>,
context: &mut Context,
context: &Context,
) -> JsObject {
// 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers.
// It may contain duplicate identifiers.

17
core/engine/src/environments/runtime/mod.rs

@ -77,11 +77,11 @@ impl EnvironmentStack {
}
/// Gets the current global environment.
pub(crate) fn global(&self) -> Gc<DeclarativeEnvironment> {
let env = self.stack[0].clone();
pub(crate) fn global(&self) -> &Gc<DeclarativeEnvironment> {
let env = &self.stack[0];
match env {
Environment::Declarative(ref env) => env.clone(),
Environment::Declarative(ref env) => env,
Environment::Object(_) => {
unreachable!("first environment should be the global environment")
}
@ -89,7 +89,7 @@ impl EnvironmentStack {
}
/// Gets the next outer function environment.
pub(crate) fn outer_function_environment(&self) -> Gc<DeclarativeEnvironment> {
pub(crate) fn outer_function_environment(&self) -> &Gc<DeclarativeEnvironment> {
for env in self
.stack
.iter()
@ -97,7 +97,7 @@ impl EnvironmentStack {
.rev()
{
if let DeclarativeEnvironmentKind::Function(_) = &env.kind() {
return env.clone();
return env;
}
}
self.global()
@ -288,11 +288,10 @@ impl EnvironmentStack {
///
/// Panics if no environment exists on the stack.
#[track_caller]
pub(crate) fn current(&self) -> Environment {
pub(crate) fn current_ref(&self) -> &Environment {
self.stack
.last()
.expect("global environment must always exist")
.clone()
}
/// Get the compile environment for the current runtime environment.
@ -502,7 +501,7 @@ impl Context {
/// are completely removed of runtime checks because the specification guarantees that runtime
/// semantics cannot add or remove lexical bindings.
pub(crate) fn find_runtime_binding(&mut self, locator: &mut BindingLocator) -> JsResult<()> {
let current = self.vm.environments.current();
let current = self.vm.environments.current_ref();
if let Some(env) = current.as_declarative() {
if !env.with() && !env.poisoned() {
return Ok(());
@ -553,7 +552,7 @@ impl Context {
&mut self,
locator: &BindingLocator,
) -> JsResult<Option<JsObject>> {
let current = self.vm.environments.current();
let current = self.vm.environments.current_ref();
if let Some(env) = current.as_declarative() {
if !env.with() {
return Ok(None);

4
core/engine/src/module/source.rs

@ -1665,7 +1665,7 @@ impl SourceTextModule {
BindingName::Name(name) => context
.vm
.environments
.current()
.current_ref()
.declarative_expect()
.kind()
.as_module()
@ -1704,7 +1704,7 @@ impl SourceTextModule {
let env = frame
.environments
.current()
.current_ref()
.as_declarative()
.cloned()
.expect("frame must have a declarative environment");

2
core/engine/src/module/synthetic.rs

@ -315,7 +315,7 @@ impl SyntheticModule {
}
let env = envs
.current()
.current_ref()
.as_declarative()
.cloned()
.expect("should have the module environment");

2
core/engine/src/vm/opcode/arguments.rs

@ -28,7 +28,7 @@ impl Operation for CreateMappedArgumentsObject {
let code = context.vm.frame().code_block().clone();
let args = context.vm.frame().arguments(&context.vm).to_vec();
let env = context.vm.environments.current();
let env = context.vm.environments.current_ref();
let arguments = MappedArguments::new(
&function_object,
&code.mapped_arguments_binding_indices,

Loading…
Cancel
Save