Skip to content

Commit

Permalink
Merge pull request #12 from zenangst/fix/crash-with-only-one-new-matc…
Browse files Browse the repository at this point in the history
…h-part-deux

Fix crash with only one new match
  • Loading branch information
zenangst authored Oct 5, 2018
2 parents 775fbf5 + c286d97 commit 6b6ae8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Differific.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Differific"
s.summary = "A fast and convenient diffing framework"
s.version = "0.5.1"
s.version = "0.5.2"
s.homepage = "https://github.com/zenangst/Differific"
s.license = 'MIT'
s.author = { "Christoffer Winterkvist" => "[email protected]" }
Expand Down
43 changes: 25 additions & 18 deletions Source/Shared/Algorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,34 @@ class Algorithm {

// 4th Pass
offset = 1
repeat {
if case let .indexInOther(otherIndex) = newArray[offset], otherIndex + 1 < oldArray.count,
case let .tableEntry(newEntry) = newArray[offset + 1],
case let .tableEntry(oldEntry) = oldArray[otherIndex + 1], newEntry === oldEntry {
newArray[offset + 1] = .indexInOther(otherIndex + 1)
oldArray[otherIndex + 1] = .indexInOther(offset + 1)
}
offset += 1
} while offset < newArray.count - 1

if newArray.count > offset {
repeat {
if case let .indexInOther(otherIndex) = newArray[offset], otherIndex + 1 < oldArray.count,
case let .tableEntry(newEntry) = newArray[offset + 1],
case let .tableEntry(oldEntry) = oldArray[otherIndex + 1], newEntry === oldEntry {
newArray[offset + 1] = .indexInOther(otherIndex + 1)
oldArray[otherIndex + 1] = .indexInOther(offset + 1)
}
offset += 1
} while offset < newArray.count - 1
}

// 5th Pass
offset = newArray.count - 1
repeat {
if case let .indexInOther(otherIndex) = newArray[offset], otherIndex - 1 >= 0,
case let .tableEntry(newEntry) = newArray[offset - 1],
case let .tableEntry(oldEntry) = oldArray[otherIndex - 1], newEntry === oldEntry {
newArray[offset - 1] = .indexInOther(otherIndex - 1)
oldArray[otherIndex - 1] = .indexInOther(offset - 1)
}
offset -= 1
} while offset > 0

if offset > newArray.count {
repeat {
if case let .indexInOther(otherIndex) = newArray[offset], otherIndex - 1 >= 0,
case let .tableEntry(newEntry) = newArray[offset - 1],
case let .tableEntry(oldEntry) = oldArray[otherIndex - 1], newEntry === oldEntry {
newArray[offset - 1] = .indexInOther(otherIndex - 1)
oldArray[otherIndex - 1] = .indexInOther(offset - 1)
}
offset -= 1
} while offset > 0
}


// Handle deleted objects
offset = 0
Expand Down

0 comments on commit 6b6ae8c

Please sign in to comment.