@@ -81,11 +81,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
8181
8282 /// Apply [`Update`]s. That's the only way to write data inside this
8383 /// relational linked chunk.
84- pub fn apply_updates ( & mut self , room_id : & RoomId , updates : & [ Update < Item , Gap > ] )
85- where
86- Item : Clone ,
87- Gap : Clone ,
88- {
84+ pub fn apply_updates ( & mut self , room_id : & RoomId , updates : Vec < Update < Item , Gap > > ) {
8985 for update in updates {
9086 match update {
9187 Update :: NewItemsChunk { previous, new, next } => {
@@ -96,8 +92,8 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
9692 insert_chunk ( & mut self . chunks , room_id, previous, new, next) ;
9793 self . items . push ( ItemRow {
9894 room_id : room_id. to_owned ( ) ,
99- position : Position :: new ( * new, 0 ) ,
100- item : Either :: Gap ( gap. clone ( ) ) ,
95+ position : Position :: new ( new, 0 ) ,
96+ item : Either :: Gap ( gap) ,
10197 } ) ;
10298 }
10399
@@ -111,7 +107,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
111107 . filter_map (
112108 |( nth, ItemRow { room_id : room_id_candidate, position, .. } ) | {
113109 ( room_id == room_id_candidate
114- && position. chunk_identifier ( ) == * chunk_identifier)
110+ && position. chunk_identifier ( ) == chunk_identifier)
115111 . then_some ( nth)
116112 } ,
117113 )
@@ -122,14 +118,12 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
122118 }
123119 }
124120
125- Update :: PushItems { at, items } => {
126- let mut at = * at;
127-
121+ Update :: PushItems { mut at, items } => {
128122 for item in items {
129123 self . items . push ( ItemRow {
130124 room_id : room_id. to_owned ( ) ,
131125 position : at,
132- item : Either :: Item ( item. clone ( ) ) ,
126+ item : Either :: Item ( item) ,
133127 } ) ;
134128 at. increment_index ( ) ;
135129 }
@@ -147,7 +141,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
147141 }
148142
149143 // Find the item to remove.
150- if position == at {
144+ if * position == at {
151145 debug_assert ! ( entry_to_remove. is_none( ) , "Found the same entry twice" ) ;
152146
153147 entry_to_remove = Some ( nth) ;
@@ -191,55 +185,55 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
191185 fn insert_chunk (
192186 chunks : & mut Vec < ChunkRow > ,
193187 room_id : & RoomId ,
194- previous : & Option < ChunkIdentifier > ,
195- new : & ChunkIdentifier ,
196- next : & Option < ChunkIdentifier > ,
188+ previous : Option < ChunkIdentifier > ,
189+ new : ChunkIdentifier ,
190+ next : Option < ChunkIdentifier > ,
197191 ) {
198192 // Find the previous chunk, and update its next chunk.
199193 if let Some ( previous) = previous {
200194 let entry_for_previous_chunk = chunks
201195 . iter_mut ( )
202196 . find ( |ChunkRow { room_id : room_id_candidate, chunk, .. } | {
203- room_id == room_id_candidate && chunk == previous
197+ room_id == room_id_candidate && * chunk == previous
204198 } )
205199 . expect ( "Previous chunk should be present" ) ;
206200
207201 // Insert the chunk.
208- entry_for_previous_chunk. next_chunk = Some ( * new) ;
202+ entry_for_previous_chunk. next_chunk = Some ( new) ;
209203 }
210204
211205 // Find the next chunk, and update its previous chunk.
212206 if let Some ( next) = next {
213207 let entry_for_next_chunk = chunks
214208 . iter_mut ( )
215209 . find ( |ChunkRow { room_id : room_id_candidate, chunk, .. } | {
216- room_id == room_id_candidate && chunk == next
210+ room_id == room_id_candidate && * chunk == next
217211 } )
218212 . expect ( "Next chunk should be present" ) ;
219213
220214 // Insert the chunk.
221- entry_for_next_chunk. previous_chunk = Some ( * new) ;
215+ entry_for_next_chunk. previous_chunk = Some ( new) ;
222216 }
223217
224218 // Insert the chunk.
225219 chunks. push ( ChunkRow {
226220 room_id : room_id. to_owned ( ) ,
227- previous_chunk : * previous,
228- chunk : * new,
229- next_chunk : * next,
221+ previous_chunk : previous,
222+ chunk : new,
223+ next_chunk : next,
230224 } ) ;
231225 }
232226
233227 fn remove_chunk (
234228 chunks : & mut Vec < ChunkRow > ,
235229 room_id : & RoomId ,
236- chunk_to_remove : & ChunkIdentifier ,
230+ chunk_to_remove : ChunkIdentifier ,
237231 ) {
238232 let entry_nth_to_remove = chunks
239233 . iter ( )
240234 . enumerate ( )
241235 . find_map ( |( nth, ChunkRow { room_id : room_id_candidate, chunk, .. } ) | {
242- ( room_id == room_id_candidate && chunk == chunk_to_remove) . then_some ( nth)
236+ ( room_id == room_id_candidate && * chunk == chunk_to_remove) . then_some ( nth)
243237 } )
244238 . expect ( "Remove an unknown chunk" ) ;
245239
@@ -294,7 +288,7 @@ mod tests {
294288
295289 relational_linked_chunk. apply_updates (
296290 room_id,
297- & [
291+ vec ! [
298292 // 0
299293 Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
300294 // 1 after 0
@@ -351,7 +345,7 @@ mod tests {
351345
352346 relational_linked_chunk. apply_updates (
353347 room_id,
354- & [
348+ vec ! [
355349 // 0
356350 Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
357351 // 1 after 0
@@ -408,7 +402,7 @@ mod tests {
408402
409403 relational_linked_chunk. apply_updates (
410404 room_id,
411- & [
405+ vec ! [
412406 // 0
413407 Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
414408 // 1 after 0
@@ -454,7 +448,7 @@ mod tests {
454448
455449 relational_linked_chunk. apply_updates (
456450 room_id,
457- & [
451+ vec ! [
458452 // new chunk (this is not mandatory for this test, but let's try to be realistic)
459453 Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
460454 // new items on 0
@@ -541,7 +535,7 @@ mod tests {
541535
542536 relational_linked_chunk. apply_updates (
543537 room_id,
544- & [
538+ vec ! [
545539 // new chunk (this is not mandatory for this test, but let's try to be realistic)
546540 Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
547541 // new items on 0
@@ -596,7 +590,7 @@ mod tests {
596590
597591 relational_linked_chunk. apply_updates (
598592 room_id,
599- & [
593+ vec ! [
600594 // new chunk
601595 Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
602596 // new chunk
@@ -670,7 +664,7 @@ mod tests {
670664 let mut relational_linked_chunk = RelationalLinkedChunk :: < char , ( ) > :: new ( ) ;
671665
672666 relational_linked_chunk
673- . apply_updates ( room_id, & [ Update :: StartReattachItems , Update :: EndReattachItems ] ) ;
667+ . apply_updates ( room_id, vec ! [ Update :: StartReattachItems , Update :: EndReattachItems ] ) ;
674668
675669 // Nothing happened.
676670 assert ! ( relational_linked_chunk. chunks. is_empty( ) ) ;
0 commit comments