@@ -64,28 +64,29 @@ public class MyersDiffWithLinearSpace<T>(
64
64
++ i
65
65
++ j
66
66
} else {
67
+ // index is less than 0 here if data.script is empty
68
+ val index = data.script.size - 1
69
+
67
70
// TODO: compress these commands
68
71
if (end1 - start1 > end2 - start2) {
69
- if (data.script.isEmpty() ||
70
- data.script[data.script.size - 1 ].endOriginal != i ||
71
- data.script[data.script.size - 1 ].deltaType != DeltaType .DELETE
72
+ if (index < 0 ||
73
+ data.script[index ].endOriginal != i ||
74
+ data.script[index ].deltaType != DeltaType .DELETE
72
75
) {
73
76
data.script.add(Change (DeltaType .DELETE , i, i + 1 , j, j))
74
77
} else {
75
- data.script[data.script.size - 1 ] =
76
- data.script[data.script.size - 1 ].copy(endOriginal = i + 1 )
78
+ data.script[index] = data.script[index].copy(endOriginal = i + 1 )
77
79
}
78
80
79
81
++ i
80
82
} else {
81
- if (data.script.isEmpty() ||
82
- data.script[data.script.size - 1 ].endRevised != j ||
83
- data.script[data.script.size - 1 ].deltaType != DeltaType .INSERT
83
+ if (index < 0 ||
84
+ data.script[index ].endRevised != j ||
85
+ data.script[index ].deltaType != DeltaType .INSERT
84
86
) {
85
87
data.script.add(Change (DeltaType .INSERT , i, i, j, j + 1 ))
86
88
} else {
87
- data.script[data.script.size - 1 ] =
88
- data.script[data.script.size - 1 ].copy(endRevised = j + 1 )
89
+ data.script[index] = data.script[index].copy(endRevised = j + 1 )
89
90
}
90
91
91
92
++ j
0 commit comments