File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
pkg/analyzer/lib/src/dart/analysis Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -38,17 +38,18 @@ class Cache<K, V> {
38
38
}
39
39
40
40
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);
48
52
}
49
- K key = _map.keys.first;
50
- V value = _map.remove (key)! ;
51
- _currentSizeBytes -= _meter (value);
52
53
}
53
54
}
54
55
}
You can’t perform that action at this time.
0 commit comments