55import 'dart:collection' show ListMixin;
66import 'dart:typed_data' show Uint32List;
77
8+ import 'package:meta/meta.dart' ;
9+
810import '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.
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 > {
1418 static const int _entryShift = 5 ;
1519
1620 static const int _bitsPerEntry = 32 ;
@@ -119,9 +123,7 @@ abstract /*mixin*/ 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 /*mixin*/ 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,12 +178,19 @@ abstract /*mixin*/ class BoolList with ListMixin<bool> {
175178 }
176179 }
177180
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+
178188 static int _lengthInWords (int bitLength) {
179189 return (bitLength + (_bitsPerEntry - 1 )) >> _entryShift;
180190 }
181191}
182192
183- class _GrowableBoolList extends BoolList {
193+ final class _GrowableBoolList extends BoolList {
184194 static const int _growthFactor = 2 ;
185195
186196 _GrowableBoolList ._withCapacity (int length, int capacity)
@@ -228,7 +238,8 @@ class _GrowableBoolList extends BoolList {
228238 }
229239}
230240
231- class _NonGrowableBoolList extends BoolList with NonGrowableListMixin <bool > {
241+ final class _NonGrowableBoolList extends BoolList
242+ with NonGrowableListMixin <bool > {
232243 _NonGrowableBoolList ._withCapacity (int length, int capacity)
233244 : super ._(
234245 Uint32List (BoolList ._lengthInWords (capacity)),
@@ -262,9 +273,7 @@ class _BoolListIterator implements Iterator<bool> {
262273
263274 if (_pos < _boolList.length) {
264275 var pos = _pos++ ;
265- _current = _boolList._data[pos >> BoolList ._entryShift] &
266- (1 << (pos & BoolList ._entrySignBitIndex)) !=
267- 0 ;
276+ _current = _boolList._getBit (pos);
268277 return true ;
269278 }
270279 _current = false ;
0 commit comments