Unverified Commit 1b76aa9e authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: fix allocation inefficiency (#63738)

### What?

- remove unnecessary clones

### Why?

### How?


Closes PACK-2847
parent d1d29cc2
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
mem::take,
}; };
use hex::encode as hex_encode; use hex::encode as hex_encode;
...@@ -423,9 +424,8 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -423,9 +424,8 @@ impl<C: Comments> VisitMut for ServerActions<C> {
fn visit_mut_fn_expr(&mut self, f: &mut FnExpr) { fn visit_mut_fn_expr(&mut self, f: &mut FnExpr) {
let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); let is_action_fn = self.get_action_info(f.function.body.as_mut(), true);
let current_declared_idents = self.declared_idents.clone(); let declared_idents_until = self.declared_idents.len();
let current_names = self.names.clone(); let current_names = take(&mut self.names);
self.names = vec![];
// Visit children // Visit children
{ {
...@@ -475,7 +475,10 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -475,7 +475,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
// Collect all the identifiers defined inside the closure and used // Collect all the identifiers defined inside the closure and used
// in the action function. With deduplication. // in the action function. With deduplication.
retain_names_from_declared_idents(&mut child_names, &current_declared_idents); retain_names_from_declared_idents(
&mut child_names,
&self.declared_idents[..declared_idents_until],
);
let maybe_new_expr = let maybe_new_expr =
self.maybe_hoist_and_create_proxy(child_names, Some(&mut f.function), None); self.maybe_hoist_and_create_proxy(child_names, Some(&mut f.function), None);
...@@ -507,8 +510,7 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -507,8 +510,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); let is_action_fn = self.get_action_info(f.function.body.as_mut(), true);
let current_declared_idents = self.declared_idents.clone(); let current_declared_idents = self.declared_idents.clone();
let current_names = self.names.clone(); let current_names = take(&mut self.names);
self.names = vec![];
{ {
// Visit children // Visit children
...@@ -581,9 +583,8 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -581,9 +583,8 @@ impl<C: Comments> VisitMut for ServerActions<C> {
true, true,
); );
let current_declared_idents = self.declared_idents.clone(); let declared_idents_until = self.declared_idents.len();
let current_names = self.names.clone(); let current_names = take(&mut self.names);
self.names = vec![];
{ {
// Visit children // Visit children
...@@ -627,7 +628,10 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -627,7 +628,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
// Collect all the identifiers defined inside the closure and used // Collect all the identifiers defined inside the closure and used
// in the action function. With deduplication. // in the action function. With deduplication.
retain_names_from_declared_idents(&mut child_names, &current_declared_idents); retain_names_from_declared_idents(
&mut child_names,
&self.declared_idents[..declared_idents_until],
);
let maybe_new_expr = self.maybe_hoist_and_create_proxy(child_names, None, Some(a)); let maybe_new_expr = self.maybe_hoist_and_create_proxy(child_names, None, Some(a));
self.rewrite_expr_to_proxy_expr = maybe_new_expr; self.rewrite_expr_to_proxy_expr = maybe_new_expr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment