From 486d8536f25c1e682711f05484d9242881b1bfbb Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 16 Aug 2026 16:09:01 +0200 Subject: [PATCH] Preallocate arrays where the new linter version would warn about it --- pkg/commands/patch/hunk.go | 3 ++- pkg/gui/context/base_context.go | 4 ++-- pkg/gui/keybindings.go | 5 +++-- pkg/integration/components/runner.go | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/commands/patch/hunk.go b/pkg/commands/patch/hunk.go index 6d0177d05..568b312a7 100644 --- a/pkg/commands/patch/hunk.go +++ b/pkg/commands/patch/hunk.go @@ -44,7 +44,8 @@ func (self *Hunk) lineCount() int { // Returns all lines in the hunk, including the header line func (self *Hunk) allLines() []*PatchLine { - lines := []*PatchLine{{Content: self.formatHeaderLine(), Kind: HUNK_HEADER}} + lines := make([]*PatchLine, 1, 1+len(self.bodyLines)) + lines[0] = &PatchLine{Content: self.formatHeaderLine(), Kind: HUNK_HEADER} lines = append(lines, self.bodyLines...) return lines } diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index 7584b5a12..67b4654a6 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -119,7 +119,7 @@ func (self *BaseContext) GetKey() types.ContextKey { } func (self *BaseContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { - bindings := []*types.Binding{} + bindings := make([]*types.Binding, 0, len(self.keybindingsFns)) for i := range self.keybindingsFns { // the first binding in the bindings array takes precedence but we want the // last keybindingsFn to take precedence to we add them in reverse @@ -216,7 +216,7 @@ func (self *BaseContext) AddOnQuitFn(fn func()) { } func (self *BaseContext) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { - bindings := []*gocui.ViewMouseBinding{} + bindings := make([]*gocui.ViewMouseBinding, 0, len(self.mouseKeybindingsFns)) for i := range self.mouseKeybindingsFns { // the first binding in the bindings array takes precedence but we want the // last keybindingsFn to take precedence to we add them in reverse diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 22d76f01b..c6ac2533e 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -295,8 +295,9 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin }, } - mouseKeybindings := []*gocui.ViewMouseBinding{} - for _, c := range gui.State.Contexts.Flatten() { + contexts := gui.State.Contexts.Flatten() + mouseKeybindings := make([]*gocui.ViewMouseBinding, 0, len(contexts)) + for _, c := range contexts { viewName := c.GetViewName() for _, binding := range c.GetKeybindings(opts) { // TODO: move all mouse keybindings into the mouse keybindings approach below diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index aaaabd0a0..098f3f2e9 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -256,14 +256,15 @@ func getLazygitCommand( return nil, err } - cmdArgs := []string{tempLazygitPath(), "-debug", "--use-config-dir=" + paths.Config()} - resolvedExtraArgs := lo.Map(test.ExtraCmdArgs(), func(arg string, _ int) string { return utils.ResolvePlaceholderString(arg, map[string]string{ "actualPath": paths.Actual(), "actualRepoPath": paths.ActualRepo(), }) }) + + cmdArgs := make([]string, 0, 3+len(resolvedExtraArgs)) + cmdArgs = append(cmdArgs, tempLazygitPath(), "-debug", "--use-config-dir="+paths.Config()) cmdArgs = append(cmdArgs, resolvedExtraArgs...) // Use a limited environment for test isolation, including pass through