From 88030e217f1ff59ed10fd65cd385fd603e17251c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 6 Oct 2015 11:30:41 -0400 Subject: [PATCH] Short-circuit degenerate cases. --- prototype/Doubt/Algorithm.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prototype/Doubt/Algorithm.swift b/prototype/Doubt/Algorithm.swift index 274a5fa9f..d8d3f6bf6 100644 --- a/prototype/Doubt/Algorithm.swift +++ b/prototype/Doubt/Algorithm.swift @@ -101,6 +101,9 @@ public enum FreeAlgorithm { 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 {