Skip to content

Commit d7626d4

Browse files
authored
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/[email protected]#Equal).
2 parents 8e04349 + 630c172 commit d7626d4

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

pkg/commands/git_commands/main_branches.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package git_commands
22

33
import (
4+
"slices"
45
"strings"
56
"sync"
67

@@ -43,7 +44,7 @@ func (self *MainBranches) Get() []string {
4344

4445
configuredMainBranches := self.c.UserConfig().Git.MainBranches
4546

46-
if self.existingMainBranches == nil || !utils.EqualSlices(self.previousMainBranches, configuredMainBranches) {
47+
if self.existingMainBranches == nil || !slices.Equal(self.previousMainBranches, configuredMainBranches) {
4748
self.existingMainBranches = self.determineMainBranches(configuredMainBranches)
4849
self.previousMainBranches = configuredMainBranches
4950
}

pkg/utils/slice.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,3 @@ func Shift[T any](slice []T) (T, []T) {
179179
slice = slice[1:]
180180
return value, slice
181181
}
182-
183-
// Compares two slices for equality
184-
func EqualSlices[T comparable](slice1 []T, slice2 []T) bool {
185-
if len(slice1) != len(slice2) {
186-
return false
187-
}
188-
189-
for i := range slice1 {
190-
if slice1[i] != slice2[i] {
191-
return false
192-
}
193-
}
194-
195-
return true
196-
}

0 commit comments

Comments
 (0)