2
2
3
3
use std:: {
4
4
fmt:: { Display , Formatter } ,
5
- mem:: { transmute_copy, ManuallyDrop } ,
5
+ hash:: BuildHasherDefault ,
6
+ mem:: { take, transmute_copy, ManuallyDrop } ,
6
7
} ;
7
8
9
+ use indexmap:: IndexSet ;
8
10
#[ cfg( feature = "concurrent-renamer" ) ]
9
11
use rayon:: prelude:: * ;
10
- use rustc_hash:: FxHashSet ;
12
+ use rustc_hash:: { FxHashSet , FxHasher } ;
11
13
use swc_atoms:: { atom, Atom } ;
12
14
use swc_common:: { collections:: AHashMap , util:: take:: Take , Mark , SyntaxContext } ;
13
15
use swc_ecma_ast:: * ;
@@ -36,6 +38,8 @@ pub(crate) struct Scope {
36
38
pub ( super ) children : Vec < Scope > ,
37
39
}
38
40
41
+ pub ( super ) type FxIndexSet < T > = IndexSet < T , BuildHasherDefault < FxHasher > > ;
42
+
39
43
#[ derive( Debug , Default ) ]
40
44
pub ( super ) struct ScopeData {
41
45
/// All identifiers used by this scope or children.
@@ -46,7 +50,7 @@ pub(super) struct ScopeData {
46
50
/// because we merge every items in children to current scope.
47
51
all : FxHashSet < Id > ,
48
52
49
- queue : Vec < Id > ,
53
+ queue : FxIndexSet < Id > ,
50
54
}
51
55
52
56
impl Scope {
@@ -62,7 +66,7 @@ impl Scope {
62
66
return ;
63
67
}
64
68
65
- self . data . queue . push ( id. clone ( ) ) ;
69
+ self . data . queue . insert ( id. clone ( ) ) ;
66
70
}
67
71
}
68
72
@@ -104,7 +108,7 @@ impl Scope {
104
108
) where
105
109
R : Renamer ,
106
110
{
107
- let queue = self . data . queue . take ( ) ;
111
+ let queue = take ( & mut self . data . queue ) ;
108
112
109
113
// let mut cloned_reverse = reverse.clone();
110
114
@@ -136,7 +140,7 @@ impl Scope {
136
140
to : & mut RenameMap ,
137
141
previous : & RenameMap ,
138
142
reverse : & mut ReverseMap ,
139
- queue : Vec < Id > ,
143
+ queue : FxIndexSet < Id > ,
140
144
preserved : & FxHashSet < Id > ,
141
145
preserved_symbols : & FxHashSet < Atom > ,
142
146
) where
@@ -208,7 +212,7 @@ impl Scope {
208
212
) where
209
213
R : Renamer ,
210
214
{
211
- let queue = self . data . queue . take ( ) ;
215
+ let queue = take ( & mut self . data . queue ) ;
212
216
213
217
let mut cloned_reverse = reverse. next ( ) ;
214
218
@@ -272,7 +276,7 @@ impl Scope {
272
276
to : & mut RenameMap ,
273
277
previous : & RenameMap ,
274
278
reverse : & mut ReverseMap ,
275
- queue : Vec < Id > ,
279
+ queue : FxIndexSet < Id > ,
276
280
preserved : & FxHashSet < Id > ,
277
281
preserved_symbols : & FxHashSet < Atom > ,
278
282
) where
0 commit comments