Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Fix performance of AllRemoteEvents::(in|de)crement_all_timeline_item_index_after #4608

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1254,10 +1254,20 @@ impl AllRemoteEvents {
/// Shift to the right all timeline item indexes that are equal to or
/// greater than `new_timeline_item_index`.
fn increment_all_timeline_item_index_after(&mut self, new_timeline_item_index: usize) {
for event_meta in self.0.iter_mut() {
// Traverse items from back to front because:
// - if `new_timeline_item_index` is 0, we need to shift all items anyways, so
// all items must be traversed,
// - otherwise, it's unlikely we want to traverse all items: the item has been
// either inserted or pushed back, so there is no need to traverse the first
// items; we can also break the iteration as soon as all timeline item index
// after `new_timeline_item_index` has been updated.
for event_meta in self.0.iter_mut().rev() {
if let Some(timeline_item_index) = event_meta.timeline_item_index.as_mut() {
if *timeline_item_index >= new_timeline_item_index {
*timeline_item_index += 1;
} else {
// Items are ordered.
break;
}
}
}
Expand All @@ -1266,10 +1276,20 @@ impl AllRemoteEvents {
/// Shift to the left all timeline item indexes that are greater than
/// `removed_wtimeline_item_index`.
fn decrement_all_timeline_item_index_after(&mut self, removed_timeline_item_index: usize) {
for event_meta in self.0.iter_mut() {
// Traverse items from back to front because:
// - if `new_timeline_item_index` is 0, we need to shift all items anyways, so
// all items must be traversed,
// - otherwise, it's unlikely we want to traverse all items: the item has been
// either inserted or pushed back, so there is no need to traverse the first
// items; we can also break the iteration as soon as all timeline item index
// after `new_timeline_item_index` has been updated.
for event_meta in self.0.iter_mut().rev() {
if let Some(timeline_item_index) = event_meta.timeline_item_index.as_mut() {
if *timeline_item_index > removed_timeline_item_index {
*timeline_item_index -= 1;
} else {
// Items are ordered.
break;
}
}
}
Expand Down
Loading