From ad9c2acef137a45327bc67484d445db626c975a9 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 22 May 2024 09:33:36 +0200 Subject: [PATCH] chore(sdk): Rename `ReattachItems` and `ReattachItemsDone`. This patch renames `ReattachItems` to `StartReattachItems` and `ReattachItemsDone` to `EndReattachItems`. This naming conveys better the idea of a _state transition_. --- .../src/event_cache/linked_chunk/as_vector.rs | 14 +++++----- .../src/event_cache/linked_chunk/mod.rs | 28 +++++++++---------- .../src/event_cache/linked_chunk/updates.rs | 16 +++++------ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs b/crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs index 1b3e16cb6..bd403fc53 100644 --- a/crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs +++ b/crates/matrix-sdk/src/event_cache/linked_chunk/as_vector.rs @@ -117,7 +117,7 @@ impl UpdateToVectorDiff { /// * [`Update::DetachLastItems`] is decreasing the length of the /// appropriate pair by the number of items to be detached; no /// [`VectorDiff`] is emitted, - /// * [`Update::ReattachItems`] and [`Update::ReattachItemsDone`] are + /// * [`Update::StartReattachItems`] and [`Update::EndReattachItems`] are /// respectively muting or unmuting the emission of [`VectorDiff`] by /// [`Update::PushItems`]. /// @@ -203,7 +203,7 @@ impl UpdateToVectorDiff { // Step 3, reattaching detached items: // // ``` - // Update::ReattachItems + // Update::StartReattachItems // Update::PushItems { // position_hint: Position(ChunkIdentifier(2), 2), // items: vec!['b'] @@ -217,7 +217,7 @@ impl UpdateToVectorDiff { // position_hint: Position(ChunkIdentifier(3), 0), // items: vec!['c'], // } - // Update::ReattachItemsDone + // Update::EndReattachItems // ``` // // To ensure an optimised behaviour of this algorithm: @@ -225,8 +225,8 @@ impl UpdateToVectorDiff { // * `Update::DetachLastItems` must not emit `VectorDiff::Remove`, // // * `Update::PushItems` must not emit `VectorDiff::Insert`s or - // `VectorDiff::Append`s if it happens after `ReattachItems` and before - // `ReattachItemsDone`. However, `Self::chunks` must always be updated. + // `VectorDiff::Append`s if it happens after `StartReattachItems` and before + // `EndReattachItems`. However, `Self::chunks` must always be updated. // // From the `VectorDiff` “point of view”, this optimisation aims at avoiding // removing items to push them again later. @@ -369,12 +369,12 @@ impl UpdateToVectorDiff { *length = new_length; } - Update::ReattachItems => { + Update::StartReattachItems => { // Entering the `reattaching` mode. mute_push_items = true; } - Update::ReattachItemsDone => { + Update::EndReattachItems => { // Exiting the `reattaching` mode. mute_push_items = false; } diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs b/crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs index 31e84ef19..9f5374bab 100644 --- a/crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs +++ b/crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs @@ -364,7 +364,7 @@ impl LinkedChunk { .push_items(items, &self.chunk_identifier_generator, &mut self.updates); if let Some(updates) = self.updates.as_mut() { - updates.push(Update::ReattachItems); + updates.push(Update::StartReattachItems); } let chunk = chunk @@ -376,7 +376,7 @@ impl LinkedChunk { ); if let Some(updates) = self.updates.as_mut() { - updates.push(Update::ReattachItemsDone); + updates.push(Update::EndReattachItems); } chunk @@ -469,7 +469,7 @@ impl LinkedChunk { ); if let Some(updates) = self.updates.as_mut() { - updates.push(Update::ReattachItems); + updates.push(Update::StartReattachItems); } let chunk = chunk @@ -486,7 +486,7 @@ impl LinkedChunk { ); if let Some(updates) = self.updates.as_mut() { - updates.push(Update::ReattachItemsDone); + updates.push(Update::EndReattachItems); } chunk @@ -1721,7 +1721,7 @@ mod tests { position_hint: Position(ChunkIdentifier(2), 0), items: vec!['y', 'z'] }, - ReattachItems, + StartReattachItems, PushItems { position_hint: Position(ChunkIdentifier(2), 2), items: vec!['e'] }, NewItemsChunk { previous: Some(ChunkIdentifier(2)), @@ -1729,7 +1729,7 @@ mod tests { next: None, }, PushItems { position_hint: Position(ChunkIdentifier(3), 0), items: vec!['f'] }, - ReattachItemsDone, + EndReattachItems, ] ); } @@ -1758,7 +1758,7 @@ mod tests { next: Some(ChunkIdentifier(1)), }, PushItems { position_hint: Position(ChunkIdentifier(4), 0), items: vec!['o'] }, - ReattachItems, + StartReattachItems, PushItems { position_hint: Position(ChunkIdentifier(4), 1), items: vec!['a', 'b'] @@ -1769,7 +1769,7 @@ mod tests { next: Some(ChunkIdentifier(1)), }, PushItems { position_hint: Position(ChunkIdentifier(5), 0), items: vec!['c'] }, - ReattachItemsDone, + EndReattachItems, ] ); } @@ -1792,9 +1792,9 @@ mod tests { position_hint: Position(ChunkIdentifier(5), 0), items: vec!['r', 's'] }, - ReattachItems, + StartReattachItems, PushItems { position_hint: Position(ChunkIdentifier(5), 2), items: vec!['c'] }, - ReattachItemsDone, + EndReattachItems, ] ); } @@ -1909,7 +1909,7 @@ mod tests { next: Some(ChunkIdentifier(1)), gap: (), }, - ReattachItems, + StartReattachItems, NewItemsChunk { previous: Some(ChunkIdentifier(2)), new: ChunkIdentifier(3), @@ -1919,7 +1919,7 @@ mod tests { position_hint: Position(ChunkIdentifier(3), 0), items: vec!['b', 'c'] }, - ReattachItemsDone, + EndReattachItems, ] ); } @@ -1941,14 +1941,14 @@ mod tests { next: Some(ChunkIdentifier(2)), gap: (), }, - ReattachItems, + StartReattachItems, NewItemsChunk { previous: Some(ChunkIdentifier(4)), new: ChunkIdentifier(5), next: Some(ChunkIdentifier(2)), }, PushItems { position_hint: Position(ChunkIdentifier(5), 0), items: vec!['a'] }, - ReattachItemsDone, + EndReattachItems, ] ); } diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk/updates.rs b/crates/matrix-sdk/src/event_cache/linked_chunk/updates.rs index 9748ee428..bc0370528 100644 --- a/crates/matrix-sdk/src/event_cache/linked_chunk/updates.rs +++ b/crates/matrix-sdk/src/event_cache/linked_chunk/updates.rs @@ -68,8 +68,8 @@ pub enum Update { /// This value is given to prevent the need for position computations by /// the update readers. Items are pushed, so the positions should be /// incrementally computed from the previous items, which requires the - /// reading of the last previous item. With `position_hint`, the update - /// readers no longer need to do so. + /// reading of the last previous item. With `at`, the update readers no + /// longer need to do so. position_hint: Position, /// The items. @@ -85,11 +85,11 @@ pub enum Update { at: Position, }, - /// Detached items (see [`Self::DetachLastItems`]) are being reattached. - ReattachItems, + /// Detached items (see [`Self::DetachLastItems`]) starts being reattached. + StartReattachItems, - /// Reattaching items (see [`Self::ReattachItems`]) is finished. - ReattachItemsDone, + /// Reattaching items (see [`Self::StartReattachItems`]) is finished. + EndReattachItems, } impl Clone for Update @@ -110,8 +110,8 @@ where Self::PushItems { position_hint: *position_hint, items: items.clone() } } Self::DetachLastItems { at } => Self::DetachLastItems { at: *at }, - Self::ReattachItems => Self::ReattachItems, - Self::ReattachItemsDone => Self::ReattachItemsDone, + Self::StartReattachItems => Self::StartReattachItems, + Self::EndReattachItems => Self::EndReattachItems, } } }