From ab9ad57ff9c7fe3733400ea5202b18f40d66feb3 Mon Sep 17 00:00:00 2001 From: Zevo Date: Fri, 4 Jun 2021 17:18:06 +0800 Subject: [PATCH] perf: User Map to optimize performance --- src/utils/collapseSourcemaps.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index 9e647c8794c..cffff82b267 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -50,6 +50,7 @@ class Link { const sources: string[] = []; const sourcesContent: string[] = []; const names: string[] = []; + const nameIndexMap: Map = new Map(); const mappings = []; @@ -93,10 +94,11 @@ class Link { ]; if (traced.name) { - let nameIndex = names.indexOf(traced.name); - if (nameIndex === -1) { + let nameIndex = nameIndexMap.get(traced.name); + if (nameIndex === undefined) { nameIndex = names.length; names.push(traced.name); + nameIndexMap.set(traced.name, nameIndex); } (tracedSegment as SourceMapSegment)[4] = nameIndex;