mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-10 17:03:20 -04:00
refactor(ui): Add ObservableItemsTransaction::has_local.
This patch implements the `has_local` method on `ObservableItemsTransaction`, which is way faster than the previous the previous solution which was to iterate over all items to find at least one local timeline item.
This commit is contained in:
@@ -320,11 +320,18 @@ impl<'observable_items> ObservableItemsTransaction<'observable_items> {
|
||||
self.push_back(timeline_item, None);
|
||||
}
|
||||
|
||||
/// Check whether there is at least one [`Local`] timeline item.
|
||||
///
|
||||
/// [`Local`]: super::EventTimelineItemKind::Local
|
||||
pub fn has_local(&self) -> bool {
|
||||
matches!(self.items.last(), Some(timeline_item) if timeline_item.is_local_echo())
|
||||
}
|
||||
|
||||
/// Push a new [`TimelineStart`] virtual timeline item.
|
||||
///
|
||||
/// # Invariant
|
||||
///
|
||||
/// A [`TimelineStart`] is always the first item if present..
|
||||
/// A [`TimelineStart`] is always the first item if present.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
||||
@@ -476,14 +476,12 @@ impl<'a> TimelineStateTransaction<'a> {
|
||||
}
|
||||
|
||||
pub(super) fn clear(&mut self) {
|
||||
let has_local_echoes = self.items.iter().any(|item| item.is_local_echo());
|
||||
|
||||
// By first checking if there are any local echoes first, we do a bit
|
||||
// more work in case some are found, but it should be worth it because
|
||||
// there will often not be any, and only emitting a single
|
||||
// `VectorDiff::Clear` should be much more efficient to process for
|
||||
// subscribers.
|
||||
if has_local_echoes {
|
||||
if self.items.has_local() {
|
||||
// Remove all remote events and virtual items that aren't date dividers.
|
||||
self.items.for_each(|entry| {
|
||||
if entry.is_remote_event()
|
||||
|
||||
Reference in New Issue
Block a user