5
5
import 'dart:collection' show ListMixin;
6
6
import 'dart:typed_data' show Uint32List;
7
7
8
+ import 'package:meta/meta.dart' ;
9
+
8
10
import 'unmodifiable_wrappers.dart' show NonGrowableListMixin;
9
11
10
12
/// A space-efficient list of boolean values.
11
13
///
12
14
/// Uses list of integers as internal storage to reduce memory usage.
13
- abstract /*mixin*/ class BoolList with ListMixin <bool > {
15
+ @sealed
16
+ // TODO: replace `interface` with `final` in the next major release.
17
+ abstract interface class BoolList with ListMixin <bool > {
14
18
static const int _entryShift = 5 ;
15
19
16
20
static const int _bitsPerEntry = 32 ;
@@ -119,9 +123,7 @@ abstract /*mixin*/ class BoolList with ListMixin<bool> {
119
123
@override
120
124
bool operator [](int index) {
121
125
RangeError .checkValidIndex (index, this , 'index' , _length);
122
- return (_data[index >> _entryShift] &
123
- (1 << (index & _entrySignBitIndex))) !=
124
- 0 ;
126
+ return _getBit (index);
125
127
}
126
128
127
129
@override
@@ -167,6 +169,7 @@ abstract /*mixin*/ class BoolList with ListMixin<bool> {
167
169
@override
168
170
Iterator <bool > get iterator => _BoolListIterator (this );
169
171
172
+ // Note: [index] is NOT checked for validity.
170
173
void _setBit (int index, bool value) {
171
174
if (value) {
172
175
_data[index >> _entryShift] | = 1 << (index & _entrySignBitIndex);
@@ -175,12 +178,19 @@ abstract /*mixin*/ class BoolList with ListMixin<bool> {
175
178
}
176
179
}
177
180
181
+ // Note: [index] is NOT checked for validity.
182
+ @pragma ('dart2js:prefer-inline' )
183
+ @pragma ('vm:prefer-inline' )
184
+ @pragma ('wasm:prefer-inline' )
185
+ bool _getBit (int index) =>
186
+ (_data[index >> _entryShift] & (1 << (index & _entrySignBitIndex))) != 0 ;
187
+
178
188
static int _lengthInWords (int bitLength) {
179
189
return (bitLength + (_bitsPerEntry - 1 )) >> _entryShift;
180
190
}
181
191
}
182
192
183
- class _GrowableBoolList extends BoolList {
193
+ final class _GrowableBoolList extends BoolList {
184
194
static const int _growthFactor = 2 ;
185
195
186
196
_GrowableBoolList ._withCapacity (int length, int capacity)
@@ -228,7 +238,8 @@ class _GrowableBoolList extends BoolList {
228
238
}
229
239
}
230
240
231
- class _NonGrowableBoolList extends BoolList with NonGrowableListMixin <bool > {
241
+ final class _NonGrowableBoolList extends BoolList
242
+ with NonGrowableListMixin <bool > {
232
243
_NonGrowableBoolList ._withCapacity (int length, int capacity)
233
244
: super ._(
234
245
Uint32List (BoolList ._lengthInWords (capacity)),
@@ -262,9 +273,7 @@ class _BoolListIterator implements Iterator<bool> {
262
273
263
274
if (_pos < _boolList.length) {
264
275
var pos = _pos++ ;
265
- _current = _boolList._data[pos >> BoolList ._entryShift] &
266
- (1 << (pos & BoolList ._entrySignBitIndex)) !=
267
- 0 ;
276
+ _current = _boolList._getBit (pos);
268
277
return true ;
269
278
}
270
279
_current = false ;
0 commit comments