From b40268744b57faf85b2e1a37b417f00be7ec6123 Mon Sep 17 00:00:00 2001 From: Zevo Date: Fri, 4 Jun 2021 17:07:49 +0800 Subject: [PATCH] perf: Use Set to optimize performance --- src/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 22573e63..f6854978 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 = 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); } @@ -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 = 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); }