1
1
mirror of https://github.com/github/semantic.git synced 2025-01-04 13:34:31 +03:00

Short-circuit degenerate cases.

This commit is contained in:
Rob Rix 2015-10-06 11:30:41 -04:00
parent 8dd605bb54
commit 88030e217f

View File

@ -101,6 +101,9 @@ public enum FreeAlgorithm<A, B> {
return f(Dictionary(elements: deleted + inserted + patched)).evaluate(equals)
case let .Roll(.ByIndex(a, b, f)):
if a.isEmpty { return f(b.map { Diff.Pure(Patch.Insert($0)) }).evaluate(equals) }
if b.isEmpty { return f(a.map { Diff.Pure(Patch.Delete($0)) }).evaluate(equals) }
let cost: Diff -> Int = { diff in
diff.map(const(1)).iterate { syntax in
switch syntax {