@@ -41,9 +41,7 @@ module.exports = function(options) {
41
41
if ( config . isListForm ) {
42
42
debug ( 'list form of results requested' ) ;
43
43
44
- tree = removeDups ( results ) ;
45
- debug ( 'removed dups from the resulting list' ) ;
46
-
44
+ tree = Array . from ( results ) ;
47
45
} else {
48
46
debug ( 'object form of results requested' ) ;
49
47
@@ -134,10 +132,10 @@ module.exports._getDependencies = function(config) {
134
132
135
133
/**
136
134
* @param {Config } config
137
- * @return {Object|String[] }
135
+ * @return {Object|Set }
138
136
*/
139
137
function traverse ( config ) {
140
- let subTree = config . isListForm ? [ ] : { } ;
138
+ let subTree = config . isListForm ? new Set ( ) : { } ;
141
139
142
140
debug ( 'traversing ' + config . filename ) ;
143
141
@@ -168,51 +166,32 @@ function traverse(config) {
168
166
localConfig . filename = d ;
169
167
170
168
if ( localConfig . isListForm ) {
171
- subTree = subTree . concat ( traverse ( localConfig ) ) ;
169
+ for ( let item of traverse ( localConfig ) ) {
170
+ subTree . add ( item ) ;
171
+ }
172
172
} else {
173
173
subTree [ d ] = traverse ( localConfig ) ;
174
174
}
175
175
}
176
176
177
177
if ( config . isListForm ) {
178
- // Prevents redundancy about each memoized step
179
- subTree = removeDups ( subTree ) ;
180
- subTree . push ( config . filename ) ;
181
- config . visited [ config . filename ] = config . visited [ config . filename ] . concat ( subTree ) ;
182
-
178
+ subTree . add ( config . filename ) ;
179
+ config . visited [ config . filename ] . push ( ...subTree ) ;
183
180
} else {
184
181
config . visited [ config . filename ] = subTree ;
185
182
}
186
183
187
184
return subTree ;
188
185
}
189
186
190
- /**
191
- * Returns a list of unique items from the array
192
- *
193
- * @param {String[] } list
194
- * @return {String[] }
195
- */
196
- function removeDups ( list ) {
197
- const cache = new Set ( ) ;
198
- const unique = [ ] ;
199
-
200
- list . forEach ( function ( item ) {
201
- if ( ! cache . has ( item ) ) {
202
- unique . push ( item ) ;
203
- cache . add ( item ) ;
204
- }
205
- } ) ;
206
-
207
- return unique ;
208
- }
209
-
210
187
// Mutate the list input to do a dereferenced modification of the user-supplied list
211
188
function dedupeNonExistent ( nonExistent ) {
212
- const deduped = removeDups ( nonExistent ) ;
213
- nonExistent . length = deduped . length ;
189
+ const deduped = new Set ( nonExistent ) ;
190
+ nonExistent . length = deduped . size ;
214
191
215
- for ( let i = 0 , l = deduped . length ; i < l ; i ++ ) {
216
- nonExistent [ i ] = deduped [ i ] ;
192
+ let i = 0 ;
193
+ for ( const elem of deduped ) {
194
+ nonExistent [ i ] = elem ;
195
+ i ++ ;
217
196
}
218
197
}
0 commit comments