@@ -81,11 +81,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
81
81
82
82
/// Apply [`Update`]s. That's the only way to write data inside this
83
83
/// 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 > > ) {
89
85
for update in updates {
90
86
match update {
91
87
Update :: NewItemsChunk { previous, new, next } => {
@@ -96,8 +92,8 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
96
92
insert_chunk ( & mut self . chunks , room_id, previous, new, next) ;
97
93
self . items . push ( ItemRow {
98
94
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) ,
101
97
} ) ;
102
98
}
103
99
@@ -111,7 +107,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
111
107
. filter_map (
112
108
|( nth, ItemRow { room_id : room_id_candidate, position, .. } ) | {
113
109
( room_id == room_id_candidate
114
- && position. chunk_identifier ( ) == * chunk_identifier)
110
+ && position. chunk_identifier ( ) == chunk_identifier)
115
111
. then_some ( nth)
116
112
} ,
117
113
)
@@ -122,14 +118,12 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
122
118
}
123
119
}
124
120
125
- Update :: PushItems { at, items } => {
126
- let mut at = * at;
127
-
121
+ Update :: PushItems { mut at, items } => {
128
122
for item in items {
129
123
self . items . push ( ItemRow {
130
124
room_id : room_id. to_owned ( ) ,
131
125
position : at,
132
- item : Either :: Item ( item. clone ( ) ) ,
126
+ item : Either :: Item ( item) ,
133
127
} ) ;
134
128
at. increment_index ( ) ;
135
129
}
@@ -147,7 +141,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
147
141
}
148
142
149
143
// Find the item to remove.
150
- if position == at {
144
+ if * position == at {
151
145
debug_assert ! ( entry_to_remove. is_none( ) , "Found the same entry twice" ) ;
152
146
153
147
entry_to_remove = Some ( nth) ;
@@ -191,55 +185,55 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
191
185
fn insert_chunk (
192
186
chunks : & mut Vec < ChunkRow > ,
193
187
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 > ,
197
191
) {
198
192
// Find the previous chunk, and update its next chunk.
199
193
if let Some ( previous) = previous {
200
194
let entry_for_previous_chunk = chunks
201
195
. iter_mut ( )
202
196
. find ( |ChunkRow { room_id : room_id_candidate, chunk, .. } | {
203
- room_id == room_id_candidate && chunk == previous
197
+ room_id == room_id_candidate && * chunk == previous
204
198
} )
205
199
. expect ( "Previous chunk should be present" ) ;
206
200
207
201
// Insert the chunk.
208
- entry_for_previous_chunk. next_chunk = Some ( * new) ;
202
+ entry_for_previous_chunk. next_chunk = Some ( new) ;
209
203
}
210
204
211
205
// Find the next chunk, and update its previous chunk.
212
206
if let Some ( next) = next {
213
207
let entry_for_next_chunk = chunks
214
208
. iter_mut ( )
215
209
. find ( |ChunkRow { room_id : room_id_candidate, chunk, .. } | {
216
- room_id == room_id_candidate && chunk == next
210
+ room_id == room_id_candidate && * chunk == next
217
211
} )
218
212
. expect ( "Next chunk should be present" ) ;
219
213
220
214
// Insert the chunk.
221
- entry_for_next_chunk. previous_chunk = Some ( * new) ;
215
+ entry_for_next_chunk. previous_chunk = Some ( new) ;
222
216
}
223
217
224
218
// Insert the chunk.
225
219
chunks. push ( ChunkRow {
226
220
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,
230
224
} ) ;
231
225
}
232
226
233
227
fn remove_chunk (
234
228
chunks : & mut Vec < ChunkRow > ,
235
229
room_id : & RoomId ,
236
- chunk_to_remove : & ChunkIdentifier ,
230
+ chunk_to_remove : ChunkIdentifier ,
237
231
) {
238
232
let entry_nth_to_remove = chunks
239
233
. iter ( )
240
234
. enumerate ( )
241
235
. 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)
243
237
} )
244
238
. expect ( "Remove an unknown chunk" ) ;
245
239
@@ -294,7 +288,7 @@ mod tests {
294
288
295
289
relational_linked_chunk. apply_updates (
296
290
room_id,
297
- & [
291
+ vec ! [
298
292
// 0
299
293
Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
300
294
// 1 after 0
@@ -351,7 +345,7 @@ mod tests {
351
345
352
346
relational_linked_chunk. apply_updates (
353
347
room_id,
354
- & [
348
+ vec ! [
355
349
// 0
356
350
Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
357
351
// 1 after 0
@@ -408,7 +402,7 @@ mod tests {
408
402
409
403
relational_linked_chunk. apply_updates (
410
404
room_id,
411
- & [
405
+ vec ! [
412
406
// 0
413
407
Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
414
408
// 1 after 0
@@ -454,7 +448,7 @@ mod tests {
454
448
455
449
relational_linked_chunk. apply_updates (
456
450
room_id,
457
- & [
451
+ vec ! [
458
452
// new chunk (this is not mandatory for this test, but let's try to be realistic)
459
453
Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
460
454
// new items on 0
@@ -541,7 +535,7 @@ mod tests {
541
535
542
536
relational_linked_chunk. apply_updates (
543
537
room_id,
544
- & [
538
+ vec ! [
545
539
// new chunk (this is not mandatory for this test, but let's try to be realistic)
546
540
Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
547
541
// new items on 0
@@ -596,7 +590,7 @@ mod tests {
596
590
597
591
relational_linked_chunk. apply_updates (
598
592
room_id,
599
- & [
593
+ vec ! [
600
594
// new chunk
601
595
Update :: NewItemsChunk { previous: None , new: CId :: new( 0 ) , next: None } ,
602
596
// new chunk
@@ -670,7 +664,7 @@ mod tests {
670
664
let mut relational_linked_chunk = RelationalLinkedChunk :: < char , ( ) > :: new ( ) ;
671
665
672
666
relational_linked_chunk
673
- . apply_updates ( room_id, & [ Update :: StartReattachItems , Update :: EndReattachItems ] ) ;
667
+ . apply_updates ( room_id, vec ! [ Update :: StartReattachItems , Update :: EndReattachItems ] ) ;
674
668
675
669
// Nothing happened.
676
670
assert ! ( relational_linked_chunk. chunks. is_empty( ) ) ;
0 commit comments