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 mut var_env = var_environment.compile_env();
let lex_env = context.vm.environments.current_compile_environment(); 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>], binding_indices: &[Option<u32>],
arguments_list: &[JsValue], arguments_list: &[JsValue],
env: &Gc<DeclarativeEnvironment>, env: &Gc<DeclarativeEnvironment>,
context: &mut Context, context: &Context,
) -> JsObject { ) -> JsObject {
// 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. // 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers.
// It may contain duplicate identifiers. // It may contain duplicate identifiers.

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

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

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

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

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

@ -315,7 +315,7 @@ impl SyntheticModule {
} }
let env = envs let env = envs
.current() .current_ref()
.as_declarative() .as_declarative()
.cloned() .cloned()
.expect("should have the module environment"); .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 code = context.vm.frame().code_block().clone();
let args = context.vm.frame().arguments(&context.vm).to_vec(); 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( let arguments = MappedArguments::new(
&function_object, &function_object,
&code.mapped_arguments_binding_indices, &code.mapped_arguments_binding_indices,

Loading…
Cancel
Save