Skip to content

Commit 5c1be4a

Browse files
committed
fixup! refactor(event cache): use the linked chunk metadata to construct the OrderTracker
Slight optimization to find the target metadata faster; all items in [0..i] are already correctly ordered.
1 parent 5a55d8b commit 5c1be4a

File tree

1 file changed

+5
-0
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+5
-0
lines changed

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,18 @@ mod private {
708708
}
709709

710710
// At this point, `current` is the identifier of the first chunk.
711+
//
711712
// Reorder the resulting vector, by going through the chain of `next` links, and
712713
// swapping items into their final position.
714+
//
715+
// Invariant in this loop: all items in [0..i[ are in their final, correct
716+
// position.
713717
let mut current = current.identifier;
714718
for i in 0..all_chunks.len() {
715719
// Find the target metadata.
716720
let j = all_chunks
717721
.iter()
722+
.rev()
718723
.position(|meta| meta.identifier == current)
719724
.expect("the target chunk must be present in the metadata");
720725
if i != j {

0 commit comments

Comments
 (0)