Index: src/0dev.org/diff/diff.go ================================================================== --- src/0dev.org/diff/diff.go +++ src/0dev.org/diff/diff.go @@ -90,17 +90,17 @@ } // Finds the largest common substring by looking at the provided match matrix // starting from (bounds.x, bounds.y) with lengths bounds.lenX, bounds.lenY func largest(bounds box, mat matrix) (result match) { - for i := bounds.x; i < bounds.lenX; i++ { + for i := bounds.x; i < bounds.lenX && result.length <= (bounds.lenX-bounds.x); i++ { var m match = search(i, bounds.y, bounds.lenX, bounds.lenY, mat) if m.length > result.length { result = m } } - for j := bounds.y + 1; j < bounds.lenY; j++ { + for j := bounds.y + 1; j < bounds.lenY && result.length <= (bounds.lenY-bounds.y); j++ { var m match = search(bounds.x, j, bounds.lenX, bounds.lenY, mat) if m.length > result.length { result = m } }