Skip to content

Commit 4ad0bfc

Browse files
committed
chore(sdk): Rename a couple of variables.
This is a clean up patch, nothing fancy.
1 parent 88953ad commit 4ad0bfc

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl UpdateToVectorDiff {
253253
//
254254
// From the `VectorDiff` “point of view”, this optimisation aims at avoiding
255255
// removing items to push them again later.
256-
let mut mute_push_items = false;
256+
let mut reattaching = false;
257257

258258
for update in updates {
259259
match update {
@@ -329,18 +329,22 @@ impl UpdateToVectorDiff {
329329
}
330330

331331
Update::PushItems { at: position, items } => {
332+
let number_of_chunks = self.chunks.len();
332333
let (offset, (chunk_index, chunk_length)) = self.map_to_offset(position);
333334

334-
// Update the length of the chunk in `self.chunks`.
335+
let is_pushing_back =
336+
chunk_index + 1 == number_of_chunks && position.index() >= *chunk_length;
337+
338+
// Add the number of items to the chunk in `self.chunks`.
335339
*chunk_length += items.len();
336340

337-
// See `mute_push_items` to learn more.
338-
if mute_push_items {
341+
// See `reattaching` to learn more.
342+
if reattaching {
339343
continue;
340344
}
341345

342346
// Optimisation: we can emit a `VectorDiff::Append` in this particular case.
343-
if chunk_index + 1 == self.chunks.len() {
347+
if is_pushing_back {
344348
diffs.push(VectorDiff::Append { values: items.into() });
345349
}
346350
// No optimisation: let's emit `VectorDiff::Insert`.
@@ -375,13 +379,13 @@ impl UpdateToVectorDiff {
375379
}
376380

377381
Update::StartReattachItems => {
378-
// Entering the `reattaching` mode.
379-
mute_push_items = true;
382+
// Entering the _reattaching_ mode.
383+
reattaching = true;
380384
}
381385

382386
Update::EndReattachItems => {
383-
// Exiting the `reattaching` mode.
384-
mute_push_items = false;
387+
// Exiting the _reattaching_ mode.
388+
reattaching = false;
385389
}
386390
}
387391
}
@@ -411,14 +415,11 @@ impl UpdateToVectorDiff {
411415

412416
// Chunk has not been found.
413417
ControlFlow::Continue(..) => {
414-
// SAFETY: Assuming `LinkedChunk` and `ObservableUpdates` are
415-
// not buggy, and assuming
416-
// `Self::chunks` is correctly initialized, it
417-
// is not possible to push items on a chunk that does not exist.
418-
// If this predicate fails,
419-
// it means `LinkedChunk` or
420-
// `ObservableUpdates` contain a bug.
421-
panic!("Pushing items: The chunk is not found");
418+
// SAFETY: Assuming `LinkedChunk` and `ObservableUpdates` are not buggy, and
419+
// assuming `Self::chunks` is correctly initialized, it is not possible to work
420+
// on a chunk that does not exist. If this predicate fails, it means
421+
// `LinkedChunk` or `ObservableUpdates` contain a bug.
422+
panic!("The chunk is not found");
422423
}
423424
}
424425
};

0 commit comments

Comments
 (0)