Skip to content

Commit dcce7bd

Browse files
nilsgstraboCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 4fe700c commit dcce7bd

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

utils/slice/utils.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,16 @@ func ElementsMatch[S ~[]E, E comparable](a, b S) bool {
8787
return false
8888
}
8989

90-
visited := make([]bool, len(b))
91-
92-
for _, aVal := range a {
93-
var found bool
94-
95-
for j, bVal := range b {
96-
if visited[j] {
97-
continue
98-
}
99-
if aVal == bVal {
100-
visited[j] = true
101-
found = true
102-
break
103-
}
104-
}
90+
counts := make(map[E]int, len(a))
91+
for _, v := range a {
92+
counts[v]++
93+
}
10594

106-
if !found {
95+
for _, v := range b {
96+
if counts[v] == 0 {
10797
return false
10898
}
99+
counts[v]--
109100
}
110101

111102
return true

0 commit comments

Comments
 (0)