Skip to content

Commit

Permalink
perf: Use Set to optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihuahuang authored and Anton Kudryavtsev committed Jun 4, 2021
1 parent 95cc2b5 commit b402687
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ export default (options: Options = {}): Plugin => {

const ids: string[] = [];
for (const module of Object.keys(chunk.modules)) {
const traversed: string[] = [];
const traversed: Set<string> = new Set();
let current = [module];
do {
const imports: string[] = [];
for (const id of current) {
if (traversed.includes(id)) continue;
if (traversed.has(id)) continue;
if (loaders.isSupported(id)) {
if (isIncluded(id)) imports.push(id);
continue;
}
traversed.push(id);
traversed.add(id);
const i = this.getModuleInfo(id);
i && imports.push(...i.importedIds);
}
Expand Down Expand Up @@ -217,17 +217,17 @@ export default (options: Options = {}): Plugin => {
const ids: string[] = [];

for (const module of Object.keys(chunk.modules)) {
const traversed: string[] = [];
const traversed: Set<string> = new Set();
let current = [module];
do {
const imports: string[] = [];
for (const id of current) {
if (traversed.includes(id)) continue;
if (traversed.has(id)) continue;
if (loaders.isSupported(id)) {
if (isIncluded(id)) imports.push(id);
continue;
}
traversed.push(id);
traversed.add(id);
const i = this.getModuleInfo(id);
i && imports.push(...i.importedIds);
}
Expand Down

0 comments on commit b402687

Please sign in to comment.