@@ -294,7 +294,7 @@ impl<const CAP: usize, Item, Gap> Ends<CAP, Item, Gap> {
294
294
// Fetch the previous chunk pointer.
295
295
let previous_ptr = unsafe { chunk_ptr. as_ref ( ) } . previous ;
296
296
297
- // Re-box the chunk, and let Rust does its job.
297
+ // Re-box the chunk, and let Rust do its job.
298
298
let _chunk_boxed = unsafe { Box :: from_raw ( chunk_ptr. as_ptr ( ) ) } ;
299
299
300
300
// Update the `current_chunk_ptr`.
@@ -569,32 +569,24 @@ impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap> {
569
569
. chunk_mut ( chunk_identifier)
570
570
. ok_or ( Error :: InvalidChunkIdentifier { identifier : chunk_identifier } ) ?;
571
571
572
- let can_unlink_chunk = match & mut chunk. content {
572
+ let current_items = match & mut chunk. content {
573
573
ChunkContent :: Gap ( ..) => {
574
574
return Err ( Error :: ChunkIsAGap { identifier : chunk_identifier } ) ;
575
575
}
576
+ ChunkContent :: Items ( current_items) => current_items,
577
+ } ;
576
578
577
- ChunkContent :: Items ( current_items) => {
578
- let current_items_length = current_items. len ( ) ;
579
-
580
- if item_index > current_items_length {
581
- return Err ( Error :: InvalidItemIndex { index : item_index } ) ;
582
- }
583
-
584
- removed_item = current_items. remove ( item_index) ;
585
-
586
- if let Some ( updates) = self . updates . as_mut ( ) {
587
- updates
588
- . push ( Update :: RemoveItem { at : Position ( chunk_identifier, item_index) } )
589
- }
579
+ if item_index > current_items. len ( ) {
580
+ return Err ( Error :: InvalidItemIndex { index : item_index } ) ;
581
+ }
590
582
591
- current_items. is_empty ( )
592
- }
593
- } ;
583
+ removed_item = current_items. remove ( item_index) ;
584
+ if let Some ( updates) = self . updates . as_mut ( ) {
585
+ updates. push ( Update :: RemoveItem { at : Position ( chunk_identifier, item_index) } )
586
+ }
594
587
595
- // If removing empty chunk is desired, and if the `chunk` can be unlinked, and
596
- // if the `chunk` is not the first one, we can remove it.
597
- if can_unlink_chunk && !chunk. is_first_chunk ( ) {
588
+ // If the chunk is empty and not the first one, we can remove it.
589
+ if current_items. is_empty ( ) && !chunk. is_first_chunk ( ) {
598
590
// Unlink `chunk`.
599
591
chunk. unlink ( self . updates . as_mut ( ) ) ;
600
592
@@ -613,7 +605,7 @@ impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap> {
613
605
if let Some ( chunk_ptr) = chunk_ptr {
614
606
// `chunk` has been unlinked.
615
607
616
- // Re-box the chunk, and let Rust does its job.
608
+ // Re-box the chunk, and let Rust do its job.
617
609
//
618
610
// SAFETY: `chunk` is unlinked and not borrowed anymore. `LinkedChunk` doesn't
619
611
// use it anymore, it's a leak. It is time to re-`Box` it and drop it.
@@ -905,7 +897,7 @@ impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap> {
905
897
// Stop borrowing `chunk`.
906
898
}
907
899
908
- // Re-box the chunk, and let Rust does its job.
900
+ // Re-box the chunk, and let Rust do its job.
909
901
//
910
902
// SAFETY: `chunk` is unlinked and not borrowed anymore. `LinkedChunk` doesn't
911
903
// use it anymore, it's a leak. It is time to re-`Box` it and drop it.
0 commit comments