Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9ff61b82
Commit
9ff61b82
authored
Mar 05, 2026
by
Matt Mastracci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce unnecessary clones
parent
86fd4ea1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
296 additions
and
27 deletions
+296
-27
linker.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/linker.rs
+10
-27
mod.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
+286
-0
No files found.
turbopack/crates/turbopack-ecmascript/src/analyzer/linker.rs
View file @
9ff61b82
use
std
::{
collections
::
hash_map
::
Entry
,
fmt
::
Display
,
future
::
Future
,
mem
::
take
,
sync
::
Arc
};
use
std
::{
collections
::
hash_map
::
Entry
,
fmt
::
Display
,
future
::
Future
,
sync
::
Arc
};
use
anyhow
::
Result
;
use
anyhow
::
Result
;
use
parking_lot
::
Mutex
;
use
parking_lot
::
Mutex
;
...
@@ -241,18 +241,14 @@ where
...
@@ -241,18 +241,14 @@ where
}
else
{
}
else
{
let
i
=
work_queue_stack
.len
();
let
i
=
work_queue_stack
.len
();
work_queue_stack
.push
(
Step
::
TemporarySlot
);
work_queue_stack
.push
(
Step
::
TemporarySlot
);
let
mut
has_early_children
=
false
;
let
has_early_children
=
val
.take_early_children
(
&
mut
|
child
|
{
val
.for_each_early_children_mut
(
&
mut
|
child
|
{
work_queue_stack
.push
(
Step
::
Enter
(
child
));
has_early_children
=
true
;
work_queue_stack
.push
(
Step
::
Enter
(
take
(
child
)));
false
});
});
if
has_early_children
{
if
has_early_children
{
work_queue_stack
[
i
]
=
Step
::
EarlyVisit
(
val
);
work_queue_stack
[
i
]
=
Step
::
EarlyVisit
(
val
);
}
else
{
}
else
{
val
.for_each_children_mut
(
&
mut
|
child
|
{
val
.take_children
(
&
mut
|
child
|
{
work_queue_stack
.push
(
Step
::
Enter
(
take
(
child
)));
work_queue_stack
.push
(
Step
::
Enter
(
child
));
false
});
});
work_queue_stack
[
i
]
=
Step
::
Leave
(
val
);
work_queue_stack
[
i
]
=
Step
::
Leave
(
val
);
}
}
...
@@ -263,11 +259,7 @@ where
...
@@ -263,11 +259,7 @@ where
// - visit the value
// - visit the value
// - insert late children and process for Leave
// - insert late children and process for Leave
Step
::
EarlyVisit
(
mut
val
)
=>
{
Step
::
EarlyVisit
(
mut
val
)
=>
{
val
.for_each_early_children_mut
(
&
mut
|
child
|
{
val
.put_early_children_from_done
(
&
mut
done
);
let
val
=
done
.pop
()
.unwrap
();
*
child
=
val
;
true
});
val
.debug_assert_total_nodes_up_to_date
();
val
.debug_assert_total_nodes_up_to_date
();
let
count
=
val
.total_nodes
();
let
count
=
val
.total_nodes
();
total_nodes
-
=
count
;
total_nodes
-
=
count
;
...
@@ -305,20 +297,15 @@ where
...
@@ -305,20 +297,15 @@ where
// Otherwise we can just process the late children
// Otherwise we can just process the late children
let
i
=
work_queue_stack
.len
();
let
i
=
work_queue_stack
.len
();
work_queue_stack
.push
(
Step
::
TemporarySlot
);
work_queue_stack
.push
(
Step
::
TemporarySlot
);
val
.for_each_late_children_mut
(
&
mut
|
child
|
{
val
.take_late_children
(
&
mut
|
child
|
{
work_queue_stack
.push
(
Step
::
Enter
(
take
(
child
)));
work_queue_stack
.push
(
Step
::
Enter
(
child
));
false
});
});
work_queue_stack
[
i
]
=
Step
::
LeaveLate
(
val
);
work_queue_stack
[
i
]
=
Step
::
LeaveLate
(
val
);
}
}
}
}
// Leave a value
// Leave a value
Step
::
Leave
(
mut
val
)
=>
{
Step
::
Leave
(
mut
val
)
=>
{
val
.for_each_children_mut
(
&
mut
|
child
|
{
val
.put_children_from_done
(
&
mut
done
);
let
val
=
done
.pop
()
.unwrap
();
*
child
=
val
;
true
});
val
.debug_assert_total_nodes_up_to_date
();
val
.debug_assert_total_nodes_up_to_date
();
let
count
=
val
.total_nodes
();
let
count
=
val
.total_nodes
();
...
@@ -338,11 +325,7 @@ where
...
@@ -338,11 +325,7 @@ where
}
}
// Leave a value from EarlyVisit
// Leave a value from EarlyVisit
Step
::
LeaveLate
(
mut
val
)
=>
{
Step
::
LeaveLate
(
mut
val
)
=>
{
val
.for_each_late_children_mut
(
&
mut
|
child
|
{
val
.put_late_children_from_done
(
&
mut
done
);
let
val
=
done
.pop
()
.unwrap
();
*
child
=
val
;
true
});
val
.debug_assert_total_nodes_up_to_date
();
val
.debug_assert_total_nodes_up_to_date
();
let
count
=
val
.total_nodes
();
let
count
=
val
.total_nodes
();
...
...
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
View file @
9ff61b82
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment