1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:14:46 -07:00

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:
linguohua 2019-06-14 22:42:14 +00:00 committed by Rebecca Stambler
parent 5aca471b1d
commit 97de5656fd

View File

@ -174,6 +174,7 @@ func shortestEditSequence(a, b []string) ([][]int, int) {
// Iterate through the maximum possible length of the SES (N+M).
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
// increments of 2 because end points for even d are on even k lines.
for k := -d; k <= d; k += 2 {
@ -197,16 +198,19 @@ func shortestEditSequence(a, b []string) ([][]int, int) {
V[k+offset] = x
// Save the state of the array.
copyV := make([]int, len(V))
copy(copyV, V)
trace[d] = copyV
// Return if we've exceeded the maximum values.
if x == M && y == N {
// Save the state of the array, and exit function
copy(copyV, V)
trace[d] = copyV
return trace, offset
}
}
// Save the state of the array, and continue loop
copy(copyV, V)
trace[d] = copyV
}
return nil, 0
}