Skip to content

Commit ff53b7b

Browse files
dinfuehrDominik Inführ
andauthored
refactor: Use array instead of Map for idToClassKey (#2321)
Switches idToClassKey to an array since ids are strictly incremented from 1. This also allows us to drop the id generator use. Co-authored-by: Dominik Inführ <dinfuehr@chromium.org>
1 parent a8c7c73 commit ff53b7b

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/HeapSnapshotManager.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ export class HeapSnapshotManager {
4444
{
4545
snapshot: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotProxy;
4646
worker: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy;
47-
// TODO: use a multimap
48-
idToClassKey: Map<number, string>;
47+
// 1-indexed array where index is the class ID.
48+
idToClassKey: string[];
4949
classKeyToId: Map<string, number>;
50-
idGenerator: () => number;
5150
}
5251
>();
5352

@@ -65,9 +64,8 @@ export class HeapSnapshotManager {
6564
this.#snapshots.set(absolutePath, {
6665
snapshot,
6766
worker,
68-
idToClassKey: new Map<number, string>(),
67+
idToClassKey: [''],
6968
classKeyToId: new Map<string, number>(),
70-
idGenerator: createIdGenerator(),
7169
});
7270

7371
return snapshot;
@@ -114,9 +112,9 @@ export class HeapSnapshotManager {
114112
const cached = this.#getCachedSnapshot(filePath);
115113
let id = cached.classKeyToId.get(classKey);
116114
if (!id) {
117-
id = cached.idGenerator();
115+
id = cached.idToClassKey.length;
118116
cached.classKeyToId.set(classKey, id);
119-
cached.idToClassKey.set(id, classKey);
117+
cached.idToClassKey.push(classKey);
120118
}
121119
return id;
122120
}
@@ -287,7 +285,7 @@ export class HeapSnapshotManager {
287285
id: number,
288286
): Promise<string | undefined> {
289287
const cached = this.#getCachedSnapshot(filePath);
290-
return cached.idToClassKey.get(id);
288+
return cached.idToClassKey[id];
291289
}
292290

293291
async #loadSnapshot(

0 commit comments

Comments
 (0)