Skip to content

Commit 2c63f59

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Fix null check in Cache.
Change-Id: I0e5924889c82fe47ea8e7e318b9a7694dc6afa61 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189421 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 08cb8be commit 2c63f59

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkg/analyzer/lib/src/dart/analysis/cache.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ class Cache<K, V> {
3838
}
3939

4040
void _evict() {
41-
while (_currentSizeBytes > _maxSizeBytes) {
42-
if (_map.isEmpty) {
43-
// Should be impossible, since _currentSizeBytes should always match
44-
// _map. But recover anyway.
45-
assert(false);
46-
_currentSizeBytes = 0;
47-
break;
41+
if (_currentSizeBytes > _maxSizeBytes) {
42+
var keysToRemove = <K>[];
43+
for (var entry in _map.entries) {
44+
keysToRemove.add(entry.key);
45+
_currentSizeBytes -= _meter(entry.value);
46+
if (_currentSizeBytes <= _maxSizeBytes) {
47+
break;
48+
}
49+
}
50+
for (var key in keysToRemove) {
51+
_map.remove(key);
4852
}
49-
K key = _map.keys.first;
50-
V value = _map.remove(key)!;
51-
_currentSizeBytes -= _meter(value);
5253
}
5354
}
5455
}

0 commit comments

Comments
 (0)