internal/lsp/diff: remove redundant memory allocate and copy operations in function 'shortestEditSequence'.
These redundant operations can cause more memory and cpu consumption. Change-Id: I54e0e23a8d1079c7991f55c897c441566c5fb2d8 GitHub-Last-Rev: 13162aa1e88ff272738c6a6675010edd2140c8a4 GitHub-Pull-Request: golang/tools#120 Reviewed-on: https://go-review.googlesource.com/c/tools/+/182478 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
5aca471b1d
commit
97de5656fd
|
@ -174,6 +174,7 @@ func shortestEditSequence(a, b []string) ([][]int, int) {
|
||||||
|
|
||||||
// Iterate through the maximum possible length of the SES (N+M).
|
// Iterate through the maximum possible length of the SES (N+M).
|
||||||
for d := 0; d <= N+M; d++ {
|
for d := 0; d <= N+M; d++ {
|
||||||
|
copyV := make([]int, len(V))
|
||||||
// k lines are represented by the equation y = x - k. We move in
|
// k lines are represented by the equation y = x - k. We move in
|
||||||
// increments of 2 because end points for even d are on even k lines.
|
// increments of 2 because end points for even d are on even k lines.
|
||||||
for k := -d; k <= d; k += 2 {
|
for k := -d; k <= d; k += 2 {
|
||||||
|
@ -197,16 +198,19 @@ func shortestEditSequence(a, b []string) ([][]int, int) {
|
||||||
|
|
||||||
V[k+offset] = x
|
V[k+offset] = x
|
||||||
|
|
||||||
// Save the state of the array.
|
// Return if we've exceeded the maximum values.
|
||||||
copyV := make([]int, len(V))
|
if x == M && y == N {
|
||||||
|
// Save the state of the array, and exit function
|
||||||
copy(copyV, V)
|
copy(copyV, V)
|
||||||
trace[d] = copyV
|
trace[d] = copyV
|
||||||
|
|
||||||
// Return if we've exceeded the maximum values.
|
|
||||||
if x == M && y == N {
|
|
||||||
return trace, offset
|
return trace, offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the state of the array, and continue loop
|
||||||
|
copy(copyV, V)
|
||||||
|
trace[d] = copyV
|
||||||
}
|
}
|
||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue