@@ -341,24 +341,21 @@ class LibraryCycleGraphLoader {
341341 ///
342342 /// A [_graphs] entry will be created for each ID in [newCycles] .
343343 void _buildGraphs (int phase, {required List <LibraryCycle > newCycles}) {
344- // Build lookup from ID to [LibraryCycle] including new and existing cycles.
345- final existingCycles = < LibraryCycle > [];
346- for (final phasedCycle in _cycles.values) {
347- if (phasedCycle.isExpiredAt (phase: phase)) continue ;
348- existingCycles.add (phasedCycle.valueAt (phase: phase));
349- }
344+ // Cycles by ID at the current phase.
350345 final cycleById = < AssetId , LibraryCycle > {};
351- for (final cycle in existingCycles) {
352- for (final id in cycle.ids) {
353- cycleById[id] = cycle;
354- }
355- }
356346 for (final cycle in newCycles) {
357347 for (final id in cycle.ids) {
358348 cycleById[id] = cycle;
359349 }
360350 }
361351
352+ /// Lookups up [id] in [cycleById] , falling back to [_cycles] if it's not
353+ /// present.
354+ LibraryCycle lookupLibraryCycle (AssetId id) =>
355+ cycleById.putIfAbsent (id, () {
356+ return _cycles[id]! .valueAt (phase: phase);
357+ });
358+
362359 // Create the graph for each cycle in [newCycles].
363360 for (final root in newCycles) {
364361 final graph = LibraryCycleGraphBuilder ()..root.replace (root);
@@ -379,7 +376,7 @@ class LibraryCycleGraphLoader {
379376 for (final id in root.ids) {
380377 final assetDeps = _assetDeps[id]! .valueAt (phase: phase);
381378 for (final dep in assetDeps.deps) {
382- final depCycle = cycleById[ dep] ! ;
379+ final depCycle = lookupLibraryCycle ( dep) ;
383380 if (identical (depCycle, root)) continue ;
384381 if (alreadyAddedChildren.add (depCycle)) {
385382 final childGraph = _graphs[dep]! .expiringValueAt (phase: phase);
0 commit comments