Skip to content

Commit 5d9852a

Browse files
committed
recent_senders [nfc]: Verify that message ID lists are sorted
The data structure and its helpers rely on message IDs being sorted, otherwise its behavior is unpredictable. This will provide useful diagnostic information when that happens. This is NFC because no change is made live, i.e. no additional sorting.
1 parent dfc0ccc commit 5d9852a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/model/recent_senders.dart

+5
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,19 @@ class MessageIdTracker {
137137
///
138138
/// [newIds] should be sorted ascending.
139139
void addAll(QueueList<int> newIds) {
140+
assert(isSortedWithoutDuplicates(newIds));
140141
if (ids.isEmpty) {
141142
ids = newIds;
142143
return;
143144
}
144145
ids = setUnion(ids, newIds);
145146
}
146147

148+
/// Remove message IDs found in [idsToRemove] from the tracker list.
149+
///
150+
/// [idsToRemove] should be sorted ascending.
147151
void removeAll(List<int> idsToRemove) {
152+
assert(isSortedWithoutDuplicates(idsToRemove));
148153
ids.removeWhere((id) => binarySearch(idsToRemove, id) != -1);
149154
}
150155

0 commit comments

Comments
 (0)