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.
15+ @sealed
16+ // TODO: replace `interface` with `final` in the next major release.
1317abstract 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 ;
0 commit comments