@@ -104,8 +104,8 @@ public enum Diff {
104
104
}
105
105
}
106
106
107
- private static func indexSections< S : AnimatableSectionModelType > ( _ sections: [ S ] ) throws -> [ S . Identity : Int ] {
108
- var indexedSections : [ S . Identity : Int ] = [ : ]
107
+ private static func indexSections< Section : AnimatableSectionModelType > ( _ sections: [ Section ] ) throws -> [ Section . Identity : Int ] {
108
+ var indexedSections : [ Section . Identity : Int ] = [ : ]
109
109
for (i, section) in sections. enumerated ( ) {
110
110
guard indexedSections [ section. identity] == nil else {
111
111
#if DEBUG
@@ -126,12 +126,12 @@ public enum Diff {
126
126
//================================================================================
127
127
// swift dictionary optimizations {
128
128
129
- private struct OptimizedIdentity < E : Hashable > : Hashable {
129
+ private struct OptimizedIdentity < Identity : Hashable > : Hashable {
130
130
131
- let identity : UnsafePointer < E >
131
+ let identity : UnsafePointer < Identity >
132
132
private let cachedHashValue : Int
133
133
134
- init ( _ identity: UnsafePointer < E > ) {
134
+ init ( _ identity: UnsafePointer < Identity > ) {
135
135
self . identity = identity
136
136
self . cachedHashValue = identity. pointee. hashValue
137
137
}
@@ -140,7 +140,7 @@ public enum Diff {
140
140
hasher. combine ( self . cachedHashValue)
141
141
}
142
142
143
- static func == ( lhs: OptimizedIdentity < E > , rhs: OptimizedIdentity < E > ) -> Bool {
143
+ static func == ( lhs: OptimizedIdentity < Identity > , rhs: OptimizedIdentity < Identity > ) -> Bool {
144
144
if lhs. hashValue != rhs. hashValue {
145
145
return false
146
146
}
@@ -157,7 +157,7 @@ public enum Diff {
157
157
private static func calculateAssociatedData< Item: IdentifiableType > (
158
158
initialItemCache: ContiguousArray < ContiguousArray < Item > > ,
159
159
finalItemCache: ContiguousArray < ContiguousArray < Item > >
160
- ) throws
160
+ ) throws
161
161
-> ( ContiguousArray < ContiguousArray < ItemAssociatedData > > , ContiguousArray < ContiguousArray < ItemAssociatedData > > ) {
162
162
163
163
typealias Identity = Item . Identity
@@ -354,15 +354,15 @@ public enum Diff {
354
354
//
355
355
// There maybe exists a better division, but time will tell.
356
356
//
357
- public static func differencesForSectionedView< S : AnimatableSectionModelType > (
358
- initialSections: [ S ] ,
359
- finalSections: [ S ] )
360
- throws -> [ Changeset < S > ] {
361
- typealias I = S . Item
357
+ public static func differencesForSectionedView< Section : AnimatableSectionModelType > (
358
+ initialSections: [ Section ] ,
359
+ finalSections: [ Section ] )
360
+ throws -> [ Changeset < Section > ] {
361
+ typealias I = Section . Item
362
362
363
- var result : [ Changeset < S > ] = [ ]
363
+ var result : [ Changeset < Section > ] = [ ]
364
364
365
- var sectionCommands = try CommandGenerator< S > . generatorForInitialSections( initialSections, finalSections: finalSections)
365
+ var sectionCommands = try CommandGenerator< Section > . generatorForInitialSections( initialSections, finalSections: finalSections)
366
366
367
367
result. append ( contentsOf: try sectionCommands. generateDeleteSectionsDeletedItemsAndUpdatedItems ( ) )
368
368
result. append ( contentsOf: try sectionCommands. generateInsertAndMoveSections ( ) )
@@ -371,20 +371,11 @@ public enum Diff {
371
371
return result
372
372
}
373
373
374
+ private struct CommandGenerator < Section: AnimatableSectionModelType > {
375
+ typealias Item = Section . Item
374
376
375
- @available ( * , deprecated, renamed: " differencesForSectionedView(initialSections:finalSections:) " )
376
- public static func differencesForSectionedView< S: AnimatableSectionModelType > (
377
- _ initialSections: [ S ] ,
378
- finalSections: [ S ] )
379
- throws -> [ Changeset < S > ] {
380
- return try differencesForSectionedView ( initialSections: initialSections, finalSections: finalSections)
381
- }
382
-
383
- private struct CommandGenerator < S: AnimatableSectionModelType > {
384
- typealias Item = S . Item
385
-
386
- let initialSections : [ S ]
387
- let finalSections : [ S ]
377
+ let initialSections : [ Section ]
378
+ let finalSections : [ Section ]
388
379
389
380
let initialSectionData : ContiguousArray < SectionAssociatedData >
390
381
let finalSectionData : ContiguousArray < SectionAssociatedData >
@@ -396,9 +387,9 @@ public enum Diff {
396
387
let finalItemCache : ContiguousArray < ContiguousArray < Item > >
397
388
398
389
static func generatorForInitialSections(
399
- _ initialSections: [ S ] ,
400
- finalSections: [ S ]
401
- ) throws -> CommandGenerator < S > {
390
+ _ initialSections: [ Section ] ,
391
+ finalSections: [ Section ]
392
+ ) throws -> CommandGenerator < Section > {
402
393
403
394
let ( initialSectionData, finalSectionData) = try calculateSectionMovements ( initialSections: initialSections, finalSections: finalSections)
404
395
@@ -417,7 +408,7 @@ public enum Diff {
417
408
finalSectionData: finalSectionData
418
409
)
419
410
420
- return CommandGenerator < S > (
411
+ return CommandGenerator < Section > (
421
412
initialSections: initialSections,
422
413
finalSections: finalSections,
423
414
@@ -526,7 +517,7 @@ public enum Diff {
526
517
return ( initialItemData, finalItemData)
527
518
}
528
519
529
- static func calculateSectionMovements( initialSections: [ S ] , finalSections: [ S ] ) throws
520
+ static func calculateSectionMovements( initialSections: [ Section ] , finalSections: [ Section ] ) throws
530
521
-> ( ContiguousArray < SectionAssociatedData > , ContiguousArray < SectionAssociatedData > ) {
531
522
532
523
let initialSectionIndexes = try Diff . indexSections ( initialSections)
@@ -609,13 +600,13 @@ public enum Diff {
609
600
return ( initialSectionData, finalSectionData)
610
601
}
611
602
612
- mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems( ) throws -> [ Changeset < S > ] {
603
+ mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems( ) throws -> [ Changeset < Section > ] {
613
604
var deletedSections = [ Int] ( )
614
605
615
606
var deletedItems = [ ItemPath] ( )
616
607
var updatedItems = [ ItemPath] ( )
617
608
618
- var afterDeleteState = [ S ] ( )
609
+ var afterDeleteState = [ Section ] ( )
619
610
620
611
// mark deleted items {
621
612
// 1rst stage again (I know, I know ...)
@@ -630,7 +621,7 @@ public enum Diff {
630
621
continue
631
622
}
632
623
633
- var afterDeleteItems : [ S . Item ] = [ ]
624
+ var afterDeleteItems : [ Section . Item ] = [ ]
634
625
for j in 0 ..< initialItems. count {
635
626
let event = initialItemData [ i] [ j] . event
636
627
switch event {
@@ -648,7 +639,7 @@ public enum Diff {
648
639
}
649
640
}
650
641
651
- afterDeleteState. append ( try S . init ( safeOriginal: initialSections [ i] , safeItems: afterDeleteItems) )
642
+ afterDeleteState. append ( try Section . init ( safeOriginal: initialSections [ i] , safeItems: afterDeleteItems) )
652
643
}
653
644
// }
654
645
@@ -664,7 +655,7 @@ public enum Diff {
664
655
) ]
665
656
}
666
657
667
- func generateInsertAndMoveSections( ) throws -> [ Changeset < S > ] {
658
+ func generateInsertAndMoveSections( ) throws -> [ Changeset < Section > ] {
668
659
669
660
var movedSections = [ ( from: Int, to: Int) ] ( )
670
661
var insertedSections = [ Int] ( )
@@ -696,7 +687,7 @@ public enum Diff {
696
687
}
697
688
698
689
// sections should be in place, but items should be original without deleted ones
699
- let sectionsAfterChange : [ S ] = try self . finalSections. enumerated ( ) . map { i, s -> S in
690
+ let sectionsAfterChange : [ Section ] = try self . finalSections. enumerated ( ) . map { i, s -> Section in
700
691
let event = self . finalSectionData [ i] . event
701
692
702
693
if event == . inserted {
@@ -707,7 +698,7 @@ public enum Diff {
707
698
let originalSectionIndex = try finalSectionData [ i] . moveIndex. unwrap ( )
708
699
let originalSection = initialSections [ originalSectionIndex]
709
700
710
- var items : [ S . Item ] = [ ]
701
+ var items : [ Section . Item ] = [ ]
711
702
items. reserveCapacity ( originalSection. items. count)
712
703
let itemAssociatedData = self . initialItemData [ originalSectionIndex]
713
704
for j in 0 ..< originalSection. items. count {
@@ -725,7 +716,7 @@ public enum Diff {
725
716
items. append ( finalItemCache [ finalIndex. sectionIndex] [ finalIndex. itemIndex] )
726
717
}
727
718
728
- let modifiedSection = try S . init ( safeOriginal: s, safeItems: items)
719
+ let modifiedSection = try Section . init ( safeOriginal: s, safeItems: items)
729
720
730
721
return modifiedSection
731
722
}
@@ -742,7 +733,7 @@ public enum Diff {
742
733
) ]
743
734
}
744
735
745
- mutating func generateInsertAndMovedItems( ) throws -> [ Changeset < S > ] {
736
+ mutating func generateInsertAndMovedItems( ) throws -> [ Changeset < Section > ] {
746
737
var insertedItems = [ ItemPath] ( )
747
738
var movedItems = [ ( from: ItemPath, to: ItemPath) ] ( )
748
739
0 commit comments