1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

refactor: use slices.Equal to simplify code (#4764)

- **PR Description**

In the Go 1.21 standard library, a new function has been introduced that
enhances code conciseness and readability. It can be find
[here](https://pkg.go.dev/slices@go1.21.1#Equal).
This commit is contained in:
Stefan Haller
2025-07-29 11:23:17 +02:00
committed by GitHub
2 changed files with 2 additions and 16 deletions

View File

@ -1,6 +1,7 @@
package git_commands package git_commands
import ( import (
"slices"
"strings" "strings"
"sync" "sync"
@ -43,7 +44,7 @@ func (self *MainBranches) Get() []string {
configuredMainBranches := self.c.UserConfig().Git.MainBranches configuredMainBranches := self.c.UserConfig().Git.MainBranches
if self.existingMainBranches == nil || !utils.EqualSlices(self.previousMainBranches, configuredMainBranches) { if self.existingMainBranches == nil || !slices.Equal(self.previousMainBranches, configuredMainBranches) {
self.existingMainBranches = self.determineMainBranches(configuredMainBranches) self.existingMainBranches = self.determineMainBranches(configuredMainBranches)
self.previousMainBranches = configuredMainBranches self.previousMainBranches = configuredMainBranches
} }

View File

@ -179,18 +179,3 @@ func Shift[T any](slice []T) (T, []T) {
slice = slice[1:] slice = slice[1:]
return value, slice return value, slice
} }
// Compares two slices for equality
func EqualSlices[T comparable](slice1 []T, slice2 []T) bool {
if len(slice1) != len(slice2) {
return false
}
for i := range slice1 {
if slice1[i] != slice2[i] {
return false
}
}
return true
}