Skip to content

Commit c559887

Browse files
add func
1 parent 726fd35 commit c559887

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/HeapSnapshotManager.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class HeapSnapshotManager {
2323
{
2424
snapshot: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotProxy;
2525
worker: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy;
26+
// TODO: use a multimap
2627
uidToClassKey: Map<number, string>;
2728
classKeyToUid: Map<string, number>;
2829
idGenerator: () => number;
@@ -84,6 +85,20 @@ export class HeapSnapshotManager {
8485
return snapshot.staticData;
8586
}
8687

88+
async getOrCreateUidForClassKey(
89+
filePath: string,
90+
classKey: string,
91+
): Promise<number> {
92+
const cached = this.#getCachedSnapshot(filePath);
93+
let uid = cached.classKeyToUid.get(classKey);
94+
if (!uid) {
95+
uid = cached.idGenerator();
96+
cached.classKeyToUid.set(classKey, uid);
97+
cached.uidToClassKey.set(uid, classKey);
98+
}
99+
return uid;
100+
}
101+
87102
async #loadSnapshot(absolutePath: string): Promise<{
88103
snapshot: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotProxy;
89104
worker: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy;

0 commit comments

Comments
 (0)