Skip to content

Commit 136522c

Browse files
committed
Revert "doc(timeline): tweak comments when inserting a new item"
This reverts commit 197da2c.
1 parent a4434d7 commit 136522c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

crates/matrix-sdk-ui/src/timeline/event_handler.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,17 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
11581158
None => self.meta.new_timeline_item(item),
11591159
};
11601160

1161+
trace!("Adding new remote timeline item after all non-local events");
1162+
1163+
// We are about to insert the `new_item`, great! Though, we try to keep
1164+
// precise insertion semantics here, in this exact order:
1165+
//
1166+
// * _push back_ when the new item is inserted after all items,
1167+
// * _push front_ when the new item is inserted at index 0,
1168+
// * _insert_ otherwise.
1169+
//
1170+
// It means that the first inserted item will generate a _push back_ for
1171+
// example.
11611172
match position {
11621173
TimelineItemPosition::Start { .. } => {
11631174
trace!("Adding new remote timeline item at the front");
@@ -1176,15 +1187,9 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
11761187
// local echo, or at the start if there is no such item.
11771188
let insert_idx = latest_event_idx.map_or(0, |idx| idx + 1);
11781189

1179-
// Try to keep precise insertion semantics here, in this exact order:
1180-
//
1181-
// * _push back_ when the new item is inserted after all items (the
1182-
// assumption
1183-
// being that this is the hot path, because most of the time new events
1184-
// come from the sync),
1185-
// * _push front_ when the new item is inserted at index 0,
1186-
// * _insert_ otherwise.
1187-
1190+
// Let's prioritize push backs because it's the hot path. Events are more
1191+
// generally added at the back because they come from the sync most of the
1192+
// time.
11881193
if insert_idx == self.items.len() {
11891194
trace!("Adding new remote timeline item at the back");
11901195
self.items.push_back(new_item);

0 commit comments

Comments
 (0)