diff --git a/pkgs/collection/CHANGELOG.md b/pkgs/collection/CHANGELOG.md index 30f8c3f7..0123f87f 100644 --- a/pkgs/collection/CHANGELOG.md +++ b/pkgs/collection/CHANGELOG.md @@ -3,6 +3,7 @@ - Add `IterableMapEntryExtension` for working on `Map` as a list of pairs, using `Map.entries`. +- Explicitly mark `BoolList` as `abstract interface` - Address diagnostics from `strict_top_level_inference`. ## 1.19.1 diff --git a/pkgs/collection/lib/src/boollist.dart b/pkgs/collection/lib/src/boollist.dart index b026d858..6b973e03 100644 --- a/pkgs/collection/lib/src/boollist.dart +++ b/pkgs/collection/lib/src/boollist.dart @@ -5,12 +5,16 @@ import 'dart:collection' show ListMixin; import 'dart:typed_data' show Uint32List; +import 'package:meta/meta.dart'; + import 'unmodifiable_wrappers.dart' show NonGrowableListMixin; /// A space-efficient list of boolean values. /// /// Uses list of integers as internal storage to reduce memory usage. -abstract /*mixin*/ class BoolList with ListMixin { +@sealed +// TODO: replace `interface` with `final` in the next major release. +abstract interface class BoolList with ListMixin { static const int _entryShift = 5; static const int _bitsPerEntry = 32; @@ -119,9 +123,7 @@ abstract /*mixin*/ class BoolList with ListMixin { @override bool operator [](int index) { RangeError.checkValidIndex(index, this, 'index', _length); - return (_data[index >> _entryShift] & - (1 << (index & _entrySignBitIndex))) != - 0; + return _getBit(index); } @override @@ -167,6 +169,7 @@ abstract /*mixin*/ class BoolList with ListMixin { @override Iterator get iterator => _BoolListIterator(this); + // Note: [index] is NOT checked for validity. void _setBit(int index, bool value) { if (value) { _data[index >> _entryShift] |= 1 << (index & _entrySignBitIndex); @@ -175,12 +178,19 @@ abstract /*mixin*/ class BoolList with ListMixin { } } + // Note: [index] is NOT checked for validity. + @pragma('dart2js:prefer-inline') + @pragma('vm:prefer-inline') + @pragma('wasm:prefer-inline') + bool _getBit(int index) => + (_data[index >> _entryShift] & (1 << (index & _entrySignBitIndex))) != 0; + static int _lengthInWords(int bitLength) { return (bitLength + (_bitsPerEntry - 1)) >> _entryShift; } } -class _GrowableBoolList extends BoolList { +final class _GrowableBoolList extends BoolList { static const int _growthFactor = 2; _GrowableBoolList._withCapacity(int length, int capacity) @@ -228,7 +238,8 @@ class _GrowableBoolList extends BoolList { } } -class _NonGrowableBoolList extends BoolList with NonGrowableListMixin { +final class _NonGrowableBoolList extends BoolList + with NonGrowableListMixin { _NonGrowableBoolList._withCapacity(int length, int capacity) : super._( Uint32List(BoolList._lengthInWords(capacity)), @@ -262,9 +273,7 @@ class _BoolListIterator implements Iterator { if (_pos < _boolList.length) { var pos = _pos++; - _current = _boolList._data[pos >> BoolList._entryShift] & - (1 << (pos & BoolList._entrySignBitIndex)) != - 0; + _current = _boolList._getBit(pos); return true; } _current = false; diff --git a/pkgs/collection/pubspec.yaml b/pkgs/collection/pubspec.yaml index 26eb4b93..b6ba057a 100644 --- a/pkgs/collection/pubspec.yaml +++ b/pkgs/collection/pubspec.yaml @@ -12,6 +12,9 @@ topics: environment: sdk: ^3.4.0 +dependencies: + meta: ^1.16.0 + dev_dependencies: benchmark_harness: ^2.3.1 dart_flutter_team_lints: ^3.0.0