Skip to content

Commit c0d8bf8

Browse files
committed
go with @Sealed for BoolList for now
1 parent 80a7330 commit c0d8bf8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pkgs/collection/lib/src/boollist.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import 'dart:collection' show ListMixin;
66
import 'dart:typed_data' show Uint32List;
77

8+
import 'package:meta/meta.dart';
9+
810
import 'unmodifiable_wrappers.dart' show NonGrowableListMixin;
911

1012
/// A space-efficient list of boolean values.
1113
///
1214
/// Uses list of integers as internal storage to reduce memory usage.
15+
@sealed
16+
// TODO: replace `interface` with `final` in the next major release.
1317
abstract interface class BoolList with ListMixin<bool> {
1418
static const int _entryShift = 5;
1519

@@ -119,9 +123,7 @@ abstract interface class BoolList with ListMixin<bool> {
119123
@override
120124
bool operator [](int index) {
121125
RangeError.checkValidIndex(index, this, 'index', _length);
122-
return (_data[index >> _entryShift] &
123-
(1 << (index & _entrySignBitIndex))) !=
124-
0;
126+
return _getBit(index);
125127
}
126128

127129
@override
@@ -167,6 +169,7 @@ abstract interface class BoolList with ListMixin<bool> {
167169
@override
168170
Iterator<bool> get iterator => _BoolListIterator(this);
169171

172+
/// Note: [index] is NOT checked for validity.
170173
void _setBit(int index, bool value) {
171174
if (value) {
172175
_data[index >> _entryShift] |= 1 << (index & _entrySignBitIndex);
@@ -175,6 +178,10 @@ abstract interface class BoolList with ListMixin<bool> {
175178
}
176179
}
177180

181+
/// Note: [index] is NOT checked for validity.
182+
bool _getBit(int index) =>
183+
(_data[index >> _entryShift] & (1 << (index & _entrySignBitIndex))) != 0;
184+
178185
static int _lengthInWords(int bitLength) {
179186
return (bitLength + (_bitsPerEntry - 1)) >> _entryShift;
180187
}
@@ -263,9 +270,7 @@ class _BoolListIterator implements Iterator<bool> {
263270

264271
if (_pos < _boolList.length) {
265272
var pos = _pos++;
266-
_current = _boolList._data[pos >> BoolList._entryShift] &
267-
(1 << (pos & BoolList._entrySignBitIndex)) !=
268-
0;
273+
_current = _boolList._getBit(pos);
269274
return true;
270275
}
271276
_current = false;

pkgs/collection/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ topics:
1212
environment:
1313
sdk: ^3.4.0
1414

15+
dependencies:
16+
meta: ^1.16.0
17+
1518
dev_dependencies:
1619
benchmark_harness: ^2.3.1
1720
dart_flutter_team_lints: ^3.0.0

0 commit comments

Comments
 (0)