Skip to content

Commit 9c5f846

Browse files
committed
remove some allocations
1 parent faaa1ee commit 9c5f846

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

crates/oxc_mangler/src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ impl Mangler {
136136

137137
let mut slot_liveness: std::vec::Vec<FixedBitSet> = vec![];
138138

139-
// Walk the scope tree and compute the slot number for each scope
140139
let mut tmp_bindings = std::vec::Vec::with_capacity(100);
140+
let mut reusable_slots = std::vec::Vec::new();
141+
// Walk the scope tree and compute the slot number for each scope
141142
for scope_id in iter::once(scope_tree.root_scope_id())
142143
.chain(scope_tree.iter_all_child_ids(scope_tree.root_scope_id()))
143144
{
@@ -153,19 +154,20 @@ impl Mangler {
153154
.find(|s_id| scope_tree.get_flags(*s_id).is_var())
154155
.unwrap_or(scope_tree.root_scope_id());
155156

156-
let reusable_slots = Vec::from_iter_in(
157+
reusable_slots.clear();
158+
reusable_slots.extend(
157159
slot_liveness
158160
.iter()
159161
.enumerate()
160162
.filter(|(_, slot_liveness)| !slot_liveness.contains(scope_id.index()))
161163
.map(|(slot, _)| slot)
162164
.take(bindings.len()),
163-
&allocator,
164165
);
165166

166167
let remaining_count = bindings.len() - reusable_slots.len();
167168

168-
let assignable_slots = reusable_slots.into_iter().chain(slot..slot + remaining_count);
169+
reusable_slots.extend(slot..slot + remaining_count);
170+
169171
slot += remaining_count;
170172
if slot_liveness.len() < slot {
171173
slot_liveness.resize_with(slot, || FixedBitSet::with_capacity(scope_tree.len()));
@@ -175,7 +177,9 @@ impl Mangler {
175177
tmp_bindings.clear();
176178
tmp_bindings.extend(bindings.values().copied());
177179
tmp_bindings.sort_unstable();
178-
for (symbol_id, assigned_slot) in tmp_bindings.iter().zip(assignable_slots) {
180+
for (symbol_id, assigned_slot) in
181+
tmp_bindings.iter().zip(reusable_slots.iter().copied())
182+
{
179183
slots[symbol_id.index()] = assigned_slot;
180184

181185
let lived_scope_ids = symbol_table

0 commit comments

Comments
 (0)