@@ -109,8 +109,15 @@ class LibraryCycleGraphLoader {
109109 }
110110
111111 /// Whether there are assets to load before or at [upToPhase] .
112- bool _hasIdToLoad ({required int upToPhase}) =>
113- _idsToLoad.keys.where ((key) => key <= upToPhase).isNotEmpty;
112+ bool _hasIdToLoad ({required int upToPhase}) {
113+ final first = _idsToLoad.keys.firstOrNull;
114+ if (first == null ) return false ;
115+ if (first > upToPhase) {
116+ // Entries are sorted, so all further entries are also too high phase.
117+ return false ;
118+ }
119+ return true ;
120+ }
114121
115122 /// The phase and ID of the next asset to load before or at [upToPhase] .
116123 ///
@@ -120,11 +127,16 @@ class LibraryCycleGraphLoader {
120127 ///
121128 /// When done loading call [_removeIdToLoad] with the phase and ID.
122129 (int , AssetId ) _nextIdToLoad ({required int upToPhase}) {
123- final entry =
124- _idsToLoad.entries.where ((entry) => entry.key <= upToPhase).first;
125- final result = entry.value.last;
126- _loadingIds.add ((entry.key, result));
127- return (entry.key, result);
130+ final first = _idsToLoad.entries.first;
131+ if (first.key > upToPhase) {
132+ // Entries are sorted, so all further entries are also too high phase.
133+ throw StateError ('No such element.' );
134+ }
135+ // Return the last ID from the list of IDs at this phase because it's
136+ // cheapest to remove in `_removeIdToLoad`.
137+ final result = first.value.last;
138+ _loadingIds.add ((first.key, result));
139+ return (first.key, result);
128140 }
129141
130142 /// Removes from [_idsToLoad] .
0 commit comments