[hir] Simplify depRoot map
Use Identifier as a key, which lets us simplify lookup to no longer require an index access.
Sathya Gunasekaran committed
Mar 1, 2023 at 16:48 UTC
08c1eda7fffdee4ebc590a2cc97dc0bde3cc268e
1 file changed
+5
-5
compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts
+5
-5
@@ -272,10 +272,10 @@ function deriveMinimalDependenciesInSubtree(
272
function deriveMinimalDependencies(
273
initialDeps: Set<ReactiveScopeDependencyInfo>
274
): Set<ReactiveScopeDependency> {
275
- const depRoots = new Map<IdentifierId, [Identifier, DependencyNode]>();
275
+ const depRoots = new Map<Identifier, DependencyNode>();
276
277
for (const dep of initialDeps) {
278
- let root = depRoots.get(dep.identifier.id)?.[1];
278
+ let root = depRoots.get(dep.identifier);
279
const path = dep.path ?? [];
280
if (root == null) {
281
// roots can always be accessed unconditionally in JS
@@ -283,7 +283,7 @@ function deriveMinimalDependencies(
283
properties: new Map(),
284
accessType: PropertyAccessType.UnconditionalAccess,
285
};
286
- depRoots.set(dep.identifier.id, [dep.identifier, root]);
286
+ depRoots.set(dep.identifier, root);
287
}
288
let currNode: DependencyNode = root;
289
@@ -314,7 +314,7 @@ function deriveMinimalDependencies(
314
}
315
316
const results = new Set<ReactiveScopeDependency>();
317
- for (const [_, [rootId, rootNode]] of depRoots) {
317
+ for (const [root, rootNode] of depRoots.entries()) {
318
const deps = deriveMinimalDependenciesInSubtree(rootNode);
319
invariant(
320
deps.every(
@@ -325,7 +325,7 @@ function deriveMinimalDependencies(
325
326
for (const dep of deps) {
327
results.add({
328
- identifier: rootId,
328
+ identifier: root,
329
path: dep.relativePath,
330
});
331
}