Skip to content

Commit 137fc9c

Browse files
committed
refactor(event cache): remove EventLinkedChunk::push_gap from the public API
it's only used internally (and in tests), and it's not doing much, so we can inline it as call sites instead.
1 parent 40a4c9a commit 137fc9c

File tree

1 file changed

+8
-48
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+8
-48
lines changed

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

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ impl EventLinkedChunk {
9494
self.chunks.push_items_back(events);
9595
}
9696

97-
/// Push a gap after all events or gaps.
98-
pub fn push_gap(&mut self, gap: Gap) {
99-
self.chunks.push_gap_back(gap);
100-
}
101-
10297
/// Remove an empty chunk at the given position.
10398
///
10499
/// Note: the chunk must either be a gap, or an empty items chunk, and it
@@ -308,7 +303,7 @@ impl EventLinkedChunk {
308303
(chunk.is_items() && chunk.num_items() == 0).then_some(chunk.identifier())
309304
});
310305

311-
self.push_gap(new_gap);
306+
self.chunks.push_gap_back(new_gap);
312307

313308
if let Some(prev_chunk_to_remove) = prev_chunk_to_remove {
314309
self.remove_empty_chunk_at(prev_chunk_to_remove)
@@ -384,7 +379,7 @@ impl EventLinkedChunk {
384379
.insert_gap_at(new_gap, new_pos)
385380
.expect("events_chunk_pos represents a valid chunk position");
386381
} else {
387-
self.push_gap(new_gap);
382+
self.chunks.push_gap_back(new_gap);
388383
}
389384
}
390385

@@ -586,41 +581,6 @@ mod tests {
586581
);
587582
}
588583

589-
#[test]
590-
fn test_push_gap() {
591-
let (event_id_0, event_0) = new_event("$ev0");
592-
let (event_id_1, event_1) = new_event("$ev1");
593-
594-
let mut linked_chunk = EventLinkedChunk::new();
595-
596-
linked_chunk.push_events([event_0]);
597-
linked_chunk.push_gap(Gap { prev_token: "hello".to_owned() });
598-
linked_chunk.push_events([event_1]);
599-
600-
assert_events_eq!(
601-
linked_chunk.events(),
602-
[
603-
(event_id_0 at (0, 0)),
604-
(event_id_1 at (2, 0)),
605-
]
606-
);
607-
608-
{
609-
let mut chunks = linked_chunk.chunks();
610-
611-
assert_let!(Some(chunk) = chunks.next());
612-
assert!(chunk.is_items());
613-
614-
assert_let!(Some(chunk) = chunks.next());
615-
assert!(chunk.is_gap());
616-
617-
assert_let!(Some(chunk) = chunks.next());
618-
assert!(chunk.is_items());
619-
620-
assert!(chunks.next().is_none());
621-
}
622-
}
623-
624584
#[test]
625585
fn test_replace_gap_at() {
626586
let (event_id_0, event_0) = new_event("$ev0");
@@ -630,7 +590,7 @@ mod tests {
630590
let mut linked_chunk = EventLinkedChunk::new();
631591

632592
linked_chunk.push_events([event_0]);
633-
linked_chunk.push_gap(Gap { prev_token: "hello".to_owned() });
593+
linked_chunk.chunks.push_gap_back(Gap { prev_token: "hello".to_owned() });
634594

635595
let gap_chunk_id = linked_chunk
636596
.chunks()
@@ -670,9 +630,9 @@ mod tests {
670630
let mut linked_chunk = EventLinkedChunk::new();
671631

672632
linked_chunk.push_events([event_0, event_1]);
673-
linked_chunk.push_gap(Gap { prev_token: "middle".to_owned() });
633+
linked_chunk.chunks.push_gap_back(Gap { prev_token: "middle".to_owned() });
674634
linked_chunk.push_events([event_2]);
675-
linked_chunk.push_gap(Gap { prev_token: "end".to_owned() });
635+
linked_chunk.chunks.push_gap_back(Gap { prev_token: "end".to_owned() });
676636

677637
// Remove the first gap.
678638
let first_gap_id = linked_chunk
@@ -705,7 +665,7 @@ mod tests {
705665
// Push some events.
706666
let mut linked_chunk = EventLinkedChunk::new();
707667
linked_chunk.push_events([event_0, event_1]);
708-
linked_chunk.push_gap(Gap { prev_token: "hello".to_owned() });
668+
linked_chunk.chunks.push_gap_back(Gap { prev_token: "hello".to_owned() });
709669
linked_chunk.push_events([event_2, event_3]);
710670

711671
assert_events_eq!(
@@ -778,7 +738,7 @@ mod tests {
778738
// Push some events.
779739
let mut linked_chunk = EventLinkedChunk::new();
780740
linked_chunk.push_events([event_0, event_1]);
781-
linked_chunk.push_gap(Gap { prev_token: "raclette".to_owned() });
741+
linked_chunk.chunks.push_gap_back(Gap { prev_token: "raclette".to_owned() });
782742
linked_chunk.push_events([event_2]);
783743

784744
// Read the updates as `VectorDiff`.
@@ -833,7 +793,7 @@ mod tests {
833793
.into_event(),
834794
event_factory.text_msg("you").event_id(event_id!("$2")).into_event(),
835795
]);
836-
linked_chunk.push_gap(Gap { prev_token: "raclette".to_owned() });
796+
linked_chunk.chunks.push_gap_back(Gap { prev_token: "raclette".to_owned() });
837797

838798
// Flush updates to the order tracker.
839799
let _ = linked_chunk.updates_as_vector_diffs();

0 commit comments

Comments
 (0)