Skip to content

Commit eac8ade

Browse files
committed
Fix failing duplicate detection
1 parent b2efc81 commit eac8ade

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/Differentiator/Diff.swift

+16
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,19 @@ public enum Diff {
199199
dictionary[key] = i
200200
}
201201

202+
var finalKeys = Set<OptimizedIdentity<Identity>>()
203+
202204
for (i, items) in finalItemCache.enumerated() {
203205
for j in 0 ..< items.count {
204206
let item = items[j]
205207
var identity = item.identity
206208
let key = OptimizedIdentity(&identity)
209+
210+
if finalKeys.contains(key) {
211+
throw Error.duplicateItem(item: item)
212+
}
213+
finalKeys.insert(key)
214+
207215
guard let initialItemPathIndex = dictionary[key] else {
208216
continue
209217
}
@@ -518,8 +526,16 @@ public enum Diff {
518526
var initialSectionData = ContiguousArray<SectionAssociatedData>(repeating: SectionAssociatedData.initial, count: initialSections.count)
519527
var finalSectionData = ContiguousArray<SectionAssociatedData>(repeating: SectionAssociatedData.initial, count: finalSections.count)
520528

529+
var finalSectionIdentities = Set<Section.Identity>()
530+
521531
for (i, section) in finalSections.enumerated() {
522532
finalSectionData[i].itemCount = finalSections[i].items.count
533+
534+
if finalSectionIdentities.contains(section.identity) {
535+
throw Error.duplicateSection(section: section)
536+
}
537+
finalSectionIdentities.insert(section.identity)
538+
523539
guard let initialSectionIndex = initialSectionIndexes[section.identity] else {
524540
continue
525541
}

0 commit comments

Comments
 (0)