@@ -33,7 +33,7 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
33
33
override fun computeDiff (source : List <T >, target : List <T >, progress : DiffAlgorithmListener ? ): List <Change > {
34
34
progress?.diffStart()
35
35
val path = buildPath(source, target, progress)
36
- val result = buildRevision(path, source, target )
36
+ val result = buildRevision(path)
37
37
progress?.diffEnd()
38
38
return result
39
39
}
@@ -49,15 +49,15 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
49
49
*/
50
50
private fun buildPath (orig : List <T >, rev : List <T >, progress : DiffAlgorithmListener ? ): PathNode ? {
51
51
// these are local constants
52
- val N = orig.size
53
- val M = rev.size
54
- val MAX = N + M + 1
55
- val size = 1 + 2 * MAX
52
+ val origSize = orig.size
53
+ val revSize = rev.size
54
+ val max = origSize + revSize + 1
55
+ val size = 1 + 2 * max
56
56
val middle = size / 2
57
57
val diagonal: Array <PathNode ?> = arrayOfNulls(size)
58
58
diagonal[middle + 1 ] = PathNode (0 , - 1 , snake = true , bootstrap = true , prev = null )
59
- for (d in 0 until MAX ) {
60
- progress?.diffStep(d, MAX )
59
+ for (d in 0 until max ) {
60
+ progress?.diffStep(d, max )
61
61
var k = - d
62
62
while (k <= d) {
63
63
val kmiddle = middle + k
@@ -75,15 +75,15 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
75
75
diagonal[kminus] = null // no longer used
76
76
var j = i - k
77
77
var node = PathNode (i, j, snake = false , bootstrap = false , prev = prev)
78
- while (i < N && j < M && equalizer.invoke(orig[i], rev[j])) {
78
+ while (i < origSize && j < revSize && equalizer.invoke(orig[i], rev[j])) {
79
79
i++
80
80
j++
81
81
}
82
82
if (i != node.i) {
83
83
node = PathNode (i, j, snake = true , bootstrap = false , prev = node)
84
84
}
85
85
diagonal[kmiddle] = node
86
- if (i >= N && j >= M ) {
86
+ if (i >= origSize && j >= revSize ) {
87
87
return diagonal[kmiddle]
88
88
}
89
89
k + = 2
@@ -102,7 +102,7 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
102
102
* @return A list of [Change]s corresponding to the path.
103
103
* @throws IllegalStateException if a patch could not be built from the given path.
104
104
*/
105
- private fun buildRevision (actualPath : PathNode ? , orig : List < T >, rev : List < T > ): List <Change > {
105
+ private fun buildRevision (actualPath : PathNode ? ): List <Change > {
106
106
var path: PathNode ? = actualPath
107
107
val changes: MutableList <Change > = mutableListOf ()
108
108
if (path!! .snake) {
0 commit comments