Skip to content

Commit

Permalink
perf: User Map to optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihuahuang committed Jun 6, 2021
1 parent 9f69fe3 commit ab9ad57
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/collapseSourcemaps.ts
Expand Up @@ -50,6 +50,7 @@ class Link {
const sources: string[] = [];
const sourcesContent: string[] = [];
const names: string[] = [];
const nameIndexMap: Map<string, number> = new Map();

const mappings = [];

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ab9ad57

Please sign in to comment.