mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-21 04:46:29 +03:00
Every query about the lines of the main view, such as moving the selection to the next change block, finds out which line of which file each row shows. For every row, this joined the path that the diff states with the path of the worktree. In a diff of 300,000 lines, this took more than half of the time of the query. The lines of a diff come file by file, so remember the last path that was made absolute and reuse it while the path stays the same. Do the same in the other places that go through every line of a diff. A query over that diff now takes about 27 milliseconds instead of 63. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package helpers
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDiffLineInfoConverterIn(t *testing.T) {
|
|
worktreePath := t.TempDir()
|
|
absolutePath := filepath.Join(t.TempDir(), "d.txt")
|
|
toDiffLineInfo := diffLineInfoConverterIn(worktreePath)
|
|
|
|
lines := []parsedDiffLine{
|
|
{Path: "a.txt", Type: types.DiffLineAdded, NewLine: 1},
|
|
{Path: "a.txt", Type: types.DiffLineDeleted, NewLine: 2, OldLine: 1},
|
|
{Path: "dir/b.txt", Type: types.DiffLineContext, NewLine: 3},
|
|
{Path: absolutePath, Type: types.DiffLineAdded, NewLine: 4},
|
|
{Path: "a.txt", Type: types.DiffLineAdded, NewLine: 5},
|
|
}
|
|
expected := []types.DiffLineInfo{
|
|
{Path: filepath.Join(worktreePath, "a.txt"), Type: types.DiffLineAdded, NewLine: 1},
|
|
{Path: filepath.Join(worktreePath, "a.txt"), Type: types.DiffLineDeleted, NewLine: 2, OldLine: 1},
|
|
{Path: filepath.Join(worktreePath, "dir", "b.txt"), Type: types.DiffLineContext, NewLine: 3},
|
|
{Path: absolutePath, Type: types.DiffLineAdded, NewLine: 4},
|
|
{Path: filepath.Join(worktreePath, "a.txt"), Type: types.DiffLineAdded, NewLine: 5},
|
|
}
|
|
|
|
for i, line := range lines {
|
|
assert.Equal(t, expected[i], toDiffLineInfo(line), "line %d", i)
|
|
}
|
|
}
|