Skip to content

Commit ca1da49

Browse files
authored
Remove unused field, fix LruCache. (#4110)
1 parent 6ecd000 commit ca1da49

File tree

14 files changed

+95
-30
lines changed

14 files changed

+95
-30
lines changed

build/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.1-wip
2+
3+
- Small improvements to RAM usage.
4+
15
## 3.0.0
26

37
- Removed unused deps: `meta`, `pool`.

build/lib/src/library_cycle_graph/library_cycle_graph_loader.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class LibraryCycleGraphLoader {
7373
/// for its sorting, so earlier phases are processed first in [_nextIdToLoad].
7474
final SplayTreeMap<int, List<AssetId>> _idsToLoad = SplayTreeMap();
7575

76-
final List<(int, AssetId)> _loadingIds = [];
77-
7876
/// All loaded library cycles, by asset.
7977
final Map<AssetId, PhasedValue<LibraryCycle>> _cycles = {};
8078

@@ -136,7 +134,6 @@ class LibraryCycleGraphLoader {
136134
// Return the last ID from the list of IDs at this phase because it's
137135
// cheapest to remove in `_removeIdToLoad`.
138136
final result = first.value.last;
139-
_loadingIds.add((first.key, result));
140137
return (first.key, result);
141138
}
142139

build/lib/src/state/lru_cache.dart

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:meta/meta.dart';
6+
57
/// A basic LRU Cache.
68
class LruCache<K, V> {
79
_Entry<K, V>? _head;
@@ -55,13 +57,15 @@ class LruCache<K, V> {
5557
_currentWeightTotal -= entry.weight;
5658
_entries.remove(key);
5759

60+
// Remove from linked list.
61+
entry.previous?.next = entry.next;
62+
entry.next?.previous = entry.previous;
63+
5864
if (entry == _tail) {
5965
_tail = entry.next;
60-
_tail?.previous = null;
6166
}
6267
if (entry == _head) {
6368
_head = entry.previous;
64-
_head?.next = null;
6569
}
6670

6771
return entry.value;
@@ -75,19 +79,27 @@ class LruCache<K, V> {
7579
_tail = link.next;
7680
}
7781

78-
if (link.previous != null) {
79-
link.previous!.next = link.next;
80-
}
81-
if (link.next != null) {
82-
link.next!.previous = link.previous;
83-
}
82+
// Remove from linked list.
83+
link.previous?.next = link.next;
84+
link.next?.previous = link.previous;
8485

8586
_head?.next = link;
8687
link.previous = _head;
8788
_head = link;
8889
_tail ??= link;
8990
link.next = null;
9091
}
92+
93+
@visibleForTesting
94+
int get linkedListLength {
95+
var result = 0;
96+
var current = _head;
97+
while (current != null) {
98+
++result;
99+
current = current.previous;
100+
}
101+
return result;
102+
}
91103
}
92104

93105
/// An entry in an [LruCache] which is also a part of a doubly linked list.

build/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build
2-
version: 3.0.0
2+
version: 3.0.1-wip
33
description: A package for authoring build_runner compatible code generators.
44
repository: https://github.com/dart-lang/build/tree/master/build
55
resolution: workspace
@@ -10,14 +10,15 @@ environment:
1010
dependencies:
1111
analyzer: '>=7.4.0 <8.0.0'
1212
async: ^2.5.0
13-
build_runner_core: '9.2.0'
13+
build_runner_core: '9.2.1-wip'
1414
built_collection: ^5.1.1
1515
built_value: ^8.9.5
1616
convert: ^3.0.0
1717
crypto: ^3.0.0
1818
glob: ^2.0.0
1919
graphs: ^2.2.0
2020
logging: ^1.0.0
21+
meta: ^1.17.0
2122
package_config: ^2.1.0
2223
path: ^1.8.0
2324

build/test/state/lru_cache_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,36 @@ void main() {
120120
expect(cache['$i'], maxIndividualWeight);
121121
}
122122
});
123+
124+
test('removes also remove from linked list', () {
125+
cache['a'] = 1;
126+
expect(cache.linkedListLength, 1);
127+
cache.remove('a');
128+
expect(cache.linkedListLength, 0);
129+
});
130+
131+
test('removes also remove from middle of linked list', () {
132+
cache['a'] = 1;
133+
cache['b'] = 1;
134+
cache['c'] = 1;
135+
expect(cache.linkedListLength, 3);
136+
cache.remove('b');
137+
expect(cache.linkedListLength, 2);
138+
});
139+
140+
test('updates remove old from linked list', () {
141+
cache['a'] = 1;
142+
expect(cache.linkedListLength, 1);
143+
cache['a'] = 2;
144+
expect(cache.linkedListLength, 1);
145+
});
146+
147+
test('updates remove old from middle of linked list', () {
148+
cache['a'] = 1;
149+
cache['b'] = 1;
150+
cache['c'] = 1;
151+
expect(cache.linkedListLength, 3);
152+
cache['b'] = 2;
153+
expect(cache.linkedListLength, 3);
154+
});
123155
}

build_resolvers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.1-wip
2+
3+
- Use `build` 3.0.1.
4+
15
## 3.0.0
26

37
- Remove unused deps: `graphs`, `logging`, `stream_transform`.

build_resolvers/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_resolvers
2-
version: 3.0.0
2+
version: 3.0.1-wip
33
description: Resolve Dart code in a Builder
44
repository: https://github.com/dart-lang/build/tree/master/build_resolvers
55
resolution: workspace
@@ -10,8 +10,8 @@ environment:
1010
dependencies:
1111
analyzer: '>=7.4.0 <8.0.0'
1212
async: ^2.5.0
13-
build: '3.0.0'
14-
build_runner_core: '9.2.0'
13+
build: '3.0.1-wip'
14+
build_runner_core: '9.2.1-wip'
1515
collection: ^1.17.0
1616
convert: ^3.1.1
1717
crypto: ^3.0.0

build_runner/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.6.1-wip
2+
3+
- Use `build` 3.0.1.
4+
15
## 2.6.0
26

37
- Remove unused deps: `analyzer`, `build_resolvers`, `collection`, `http`,

build_runner/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_runner
2-
version: 2.6.0
2+
version: 2.6.1-wip
33
description: A build system for Dart code generation and modular compilation.
44
repository: https://github.com/dart-lang/build/tree/master/build_runner
55
resolution: workspace
@@ -15,10 +15,10 @@ platforms:
1515
dependencies:
1616
args: ^2.0.0
1717
async: ^2.5.0
18-
build: '3.0.0'
18+
build: '3.0.1-wip'
1919
build_config: ">=1.1.0 <1.2.0"
2020
build_daemon: ^4.0.0
21-
build_runner_core: '9.2.0'
21+
build_runner_core: '9.2.1-wip'
2222
code_builder: ^4.2.0
2323
crypto: ^3.0.0
2424
dart_style: '>=2.3.7 <4.0.0'

build_runner_core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 9.2.1-wip
2+
3+
- Use `build` 3.0.1.
4+
15
## 9.2.0
26

37
- Removed unused dev_deps: `test_process`.

0 commit comments

Comments
 (0)