@@ -104,8 +104,8 @@ public enum Diff {
104104 }
105105 }
106106
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 ] = [ : ]
109109 for (i, section) in sections. enumerated ( ) {
110110 guard indexedSections [ section. identity] == nil else {
111111 #if DEBUG
@@ -126,12 +126,12 @@ public enum Diff {
126126 //================================================================================
127127 // swift dictionary optimizations {
128128
129- private struct OptimizedIdentity < E : Hashable > : Hashable {
129+ private struct OptimizedIdentity < Identity : Hashable > : Hashable {
130130
131- let identity : UnsafePointer < E >
131+ let identity : UnsafePointer < Identity >
132132 private let cachedHashValue : Int
133133
134- init ( _ identity: UnsafePointer < E > ) {
134+ init ( _ identity: UnsafePointer < Identity > ) {
135135 self . identity = identity
136136 self . cachedHashValue = identity. pointee. hashValue
137137 }
@@ -140,7 +140,7 @@ public enum Diff {
140140 hasher. combine ( self . cachedHashValue)
141141 }
142142
143- static func == ( lhs: OptimizedIdentity < E > , rhs: OptimizedIdentity < E > ) -> Bool {
143+ static func == ( lhs: OptimizedIdentity < Identity > , rhs: OptimizedIdentity < Identity > ) -> Bool {
144144 if lhs. hashValue != rhs. hashValue {
145145 return false
146146 }
@@ -157,7 +157,7 @@ public enum Diff {
157157 private static func calculateAssociatedData< Item: IdentifiableType > (
158158 initialItemCache: ContiguousArray < ContiguousArray < Item > > ,
159159 finalItemCache: ContiguousArray < ContiguousArray < Item > >
160- ) throws
160+ ) throws
161161 -> ( ContiguousArray < ContiguousArray < ItemAssociatedData > > , ContiguousArray < ContiguousArray < ItemAssociatedData > > ) {
162162
163163 typealias Identity = Item . Identity
@@ -354,15 +354,15 @@ public enum Diff {
354354 //
355355 // There maybe exists a better division, but time will tell.
356356 //
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
362362
363- var result : [ Changeset < S > ] = [ ]
363+ var result : [ Changeset < Section > ] = [ ]
364364
365- var sectionCommands = try CommandGenerator< S > . generatorForInitialSections( initialSections, finalSections: finalSections)
365+ var sectionCommands = try CommandGenerator< Section > . generatorForInitialSections( initialSections, finalSections: finalSections)
366366
367367 result. append ( contentsOf: try sectionCommands. generateDeleteSectionsDeletedItemsAndUpdatedItems ( ) )
368368 result. append ( contentsOf: try sectionCommands. generateInsertAndMoveSections ( ) )
@@ -371,20 +371,11 @@ public enum Diff {
371371 return result
372372 }
373373
374+ private struct CommandGenerator < Section: AnimatableSectionModelType > {
375+ typealias Item = Section . Item
374376
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 ]
388379
389380 let initialSectionData : ContiguousArray < SectionAssociatedData >
390381 let finalSectionData : ContiguousArray < SectionAssociatedData >
@@ -396,9 +387,9 @@ public enum Diff {
396387 let finalItemCache : ContiguousArray < ContiguousArray < Item > >
397388
398389 static func generatorForInitialSections(
399- _ initialSections: [ S ] ,
400- finalSections: [ S ]
401- ) throws -> CommandGenerator < S > {
390+ _ initialSections: [ Section ] ,
391+ finalSections: [ Section ]
392+ ) throws -> CommandGenerator < Section > {
402393
403394 let ( initialSectionData, finalSectionData) = try calculateSectionMovements ( initialSections: initialSections, finalSections: finalSections)
404395
@@ -417,7 +408,7 @@ public enum Diff {
417408 finalSectionData: finalSectionData
418409 )
419410
420- return CommandGenerator < S > (
411+ return CommandGenerator < Section > (
421412 initialSections: initialSections,
422413 finalSections: finalSections,
423414
@@ -526,7 +517,7 @@ public enum Diff {
526517 return ( initialItemData, finalItemData)
527518 }
528519
529- static func calculateSectionMovements( initialSections: [ S ] , finalSections: [ S ] ) throws
520+ static func calculateSectionMovements( initialSections: [ Section ] , finalSections: [ Section ] ) throws
530521 -> ( ContiguousArray < SectionAssociatedData > , ContiguousArray < SectionAssociatedData > ) {
531522
532523 let initialSectionIndexes = try Diff . indexSections ( initialSections)
@@ -609,13 +600,13 @@ public enum Diff {
609600 return ( initialSectionData, finalSectionData)
610601 }
611602
612- mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems( ) throws -> [ Changeset < S > ] {
603+ mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems( ) throws -> [ Changeset < Section > ] {
613604 var deletedSections = [ Int] ( )
614605
615606 var deletedItems = [ ItemPath] ( )
616607 var updatedItems = [ ItemPath] ( )
617608
618- var afterDeleteState = [ S ] ( )
609+ var afterDeleteState = [ Section ] ( )
619610
620611 // mark deleted items {
621612 // 1rst stage again (I know, I know ...)
@@ -630,7 +621,7 @@ public enum Diff {
630621 continue
631622 }
632623
633- var afterDeleteItems : [ S . Item ] = [ ]
624+ var afterDeleteItems : [ Section . Item ] = [ ]
634625 for j in 0 ..< initialItems. count {
635626 let event = initialItemData [ i] [ j] . event
636627 switch event {
@@ -648,7 +639,7 @@ public enum Diff {
648639 }
649640 }
650641
651- afterDeleteState. append ( try S . init ( safeOriginal: initialSections [ i] , safeItems: afterDeleteItems) )
642+ afterDeleteState. append ( try Section . init ( safeOriginal: initialSections [ i] , safeItems: afterDeleteItems) )
652643 }
653644 // }
654645
@@ -664,7 +655,7 @@ public enum Diff {
664655 ) ]
665656 }
666657
667- func generateInsertAndMoveSections( ) throws -> [ Changeset < S > ] {
658+ func generateInsertAndMoveSections( ) throws -> [ Changeset < Section > ] {
668659
669660 var movedSections = [ ( from: Int, to: Int) ] ( )
670661 var insertedSections = [ Int] ( )
@@ -696,7 +687,7 @@ public enum Diff {
696687 }
697688
698689 // 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
700691 let event = self . finalSectionData [ i] . event
701692
702693 if event == . inserted {
@@ -707,7 +698,7 @@ public enum Diff {
707698 let originalSectionIndex = try finalSectionData [ i] . moveIndex. unwrap ( )
708699 let originalSection = initialSections [ originalSectionIndex]
709700
710- var items : [ S . Item ] = [ ]
701+ var items : [ Section . Item ] = [ ]
711702 items. reserveCapacity ( originalSection. items. count)
712703 let itemAssociatedData = self . initialItemData [ originalSectionIndex]
713704 for j in 0 ..< originalSection. items. count {
@@ -725,7 +716,7 @@ public enum Diff {
725716 items. append ( finalItemCache [ finalIndex. sectionIndex] [ finalIndex. itemIndex] )
726717 }
727718
728- let modifiedSection = try S . init ( safeOriginal: s, safeItems: items)
719+ let modifiedSection = try Section . init ( safeOriginal: s, safeItems: items)
729720
730721 return modifiedSection
731722 }
@@ -742,7 +733,7 @@ public enum Diff {
742733 ) ]
743734 }
744735
745- mutating func generateInsertAndMovedItems( ) throws -> [ Changeset < S > ] {
736+ mutating func generateInsertAndMovedItems( ) throws -> [ Changeset < Section > ] {
746737 var insertedItems = [ ItemPath] ( )
747738 var movedItems = [ ( from: ItemPath, to: ItemPath) ] ( )
748739
0 commit comments