Skip to content

Commit

Permalink
refactor: extract to local variable to avoid multiple computations
Browse files Browse the repository at this point in the history
  • Loading branch information
lppedd committed Jun 11, 2024
1 parent ed5830c commit 2df15c0
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,29 @@ public class MyersDiffWithLinearSpace<T>(
++i
++j
} else {
// Remember size can be less than 0 here
val size = data.script.size - 1

// TODO: compress these commands
if (end1 - start1 > end2 - start2) {
if (data.script.isEmpty() ||
data.script[data.script.size - 1].endOriginal != i ||
data.script[data.script.size - 1].deltaType != DeltaType.DELETE
if (size < 1 ||
data.script[size].endOriginal != i ||
data.script[size].deltaType != DeltaType.DELETE
) {
data.script.add(Change(DeltaType.DELETE, i, i + 1, j, j))
} else {
data.script[data.script.size - 1] =
data.script[data.script.size - 1].copy(endOriginal = i + 1)
data.script[size] = data.script[size].copy(endOriginal = i + 1)
}

++i
} else {
if (data.script.isEmpty() ||
data.script[data.script.size - 1].endRevised != j ||
data.script[data.script.size - 1].deltaType != DeltaType.INSERT
if (size < 1 ||
data.script[size].endRevised != j ||
data.script[size].deltaType != DeltaType.INSERT
) {
data.script.add(Change(DeltaType.INSERT, i, i, j, j + 1))
} else {
data.script[data.script.size - 1] =
data.script[data.script.size - 1].copy(endRevised = j + 1)
data.script[size] = data.script[size].copy(endRevised = j + 1)
}

++j
Expand Down

0 comments on commit 2df15c0

Please sign in to comment.