Skip to content

Commit

Permalink
Optimize BitList filling.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Sep 3, 2023
1 parent 71a4f80 commit 811a10d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/src/collection/bitlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,21 @@ const List<int> bitClearMask = [
-2147483649
];

void _fillRange(Uint32List buffer, int start, int end, bool? fill) {
void _fillRange(Uint32List buffer, int start, int end, bool value) {
if (start == end) return;
final startIndex = start >> bitShift, startBit = start & bitOffset;
final endIndex = (end - 1) >> bitShift, endBit = (end - 1) & bitOffset;
if (startIndex == endIndex) {
if (fill == true) {
if (value) {
if (startIndex == endIndex) {
buffer[startIndex] |= ((1 << (endBit - startBit + 1)) - 1) << startBit;
} else {
buffer[startIndex] &= ((1 << startBit) - 1) | (bitMask << (endBit + 1));
}
} else {
if (fill == true) {
buffer[startIndex] |= bitMask << startBit;
buffer.fillRange(startIndex + 1, endIndex, bitMask);
buffer[endIndex] |= (1 << (endBit + 1)) - 1;
}
} else {
if (startIndex == endIndex) {
buffer[startIndex] &= ((1 << startBit) - 1) | (bitMask << (endBit + 1));
} else {
buffer[startIndex] &= (1 << startBit) - 1;
buffer.fillRange(startIndex + 1, endIndex, 0);
Expand Down

0 comments on commit 811a10d

Please sign in to comment.