@@ -127,6 +127,7 @@ impl Mangler {
127
127
}
128
128
129
129
// Walk the scope tree and compute the slot number for each scope
130
+ let mut tmp_bindings = std:: vec:: Vec :: with_capacity ( 100 ) ;
130
131
for scope_id in scope_tree. descendants_from_root ( ) {
131
132
let bindings = scope_tree. get_bindings ( scope_id) ;
132
133
@@ -139,9 +140,10 @@ impl Mangler {
139
140
140
141
if !bindings. is_empty ( ) {
141
142
// Sort `bindings` in declaration order.
142
- let mut bindings = bindings. values ( ) . copied ( ) . collect :: < std:: vec:: Vec < _ > > ( ) ;
143
- bindings. sort_unstable ( ) ;
144
- for symbol_id in bindings {
143
+ tmp_bindings. clear ( ) ;
144
+ tmp_bindings. extend ( bindings. values ( ) . copied ( ) ) ;
145
+ tmp_bindings. sort_unstable ( ) ;
146
+ for symbol_id in & tmp_bindings {
145
147
slots[ symbol_id. index ( ) ] = slot;
146
148
slot += 1 ;
147
149
}
@@ -203,20 +205,22 @@ impl Mangler {
203
205
// function fa() { .. } function ga() { .. }
204
206
205
207
let mut freq_iter = frequencies. iter ( ) ;
208
+ let mut symbols_renamed_in_this_batch = std:: vec:: Vec :: with_capacity ( 100 ) ;
209
+ let mut slice_of_same_len_strings = std:: vec:: Vec :: with_capacity ( 100 ) ;
206
210
// 2. "N number of vars are going to be assigned names of the same length"
207
211
for ( _, slice_of_same_len_strings_group) in
208
212
& reserved_names. into_iter ( ) . chunk_by ( CompactStr :: len)
209
213
{
210
214
// 1. "The most frequent vars get the shorter names"
211
215
// (freq_iter is sorted by frequency from highest to lowest,
212
216
// so taking means take the N most frequent symbols remaining)
213
- let slice_of_same_len_strings = slice_of_same_len_strings_group . collect_vec ( ) ;
214
- let mut symbols_renamed_in_this_batch = freq_iter
215
- . by_ref ( )
216
- . take ( slice_of_same_len_strings . len ( ) )
217
- . collect :: < std :: vec :: Vec < _ > > ( ) ;
217
+ slice_of_same_len_strings. clear ( ) ;
218
+ slice_of_same_len_strings . extend ( slice_of_same_len_strings_group ) ;
219
+ symbols_renamed_in_this_batch . clear ( ) ;
220
+ symbols_renamed_in_this_batch
221
+ . extend ( freq_iter . by_ref ( ) . take ( slice_of_same_len_strings . len ( ) ) ) ;
218
222
219
- debug_assert ! ( symbols_renamed_in_this_batch. len( ) == slice_of_same_len_strings. len( ) ) ;
223
+ debug_assert_eq ! ( symbols_renamed_in_this_batch. len( ) , slice_of_same_len_strings. len( ) ) ;
220
224
221
225
// 2. "we assign the N names based on the order at which the vars first appear in the source."
222
226
// sorting by slot enables us to sort by the order at which the vars first appear in the source
0 commit comments