reflect.DeepEqual is a value copy that causes golang to continuously allocate memory
This commit is contained in:
parent
893b0de8fa
commit
4e2c4f92d3
2 changed files with 11 additions and 1 deletions
|
@ -155,7 +155,7 @@ func (machine *Machine) isOnline() bool {
|
|||
|
||||
func containsAddresses(inputs []string, addrs []string) bool {
|
||||
for _, addr := range addrs {
|
||||
if contains(inputs, addr) {
|
||||
if containsStr(inputs, addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
10
utils.go
10
utils.go
|
@ -269,6 +269,16 @@ func stringToIPPrefix(prefixes []string) ([]netip.Prefix, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func containsStr(ts []string, t string) bool {
|
||||
for _, v := range ts {
|
||||
if v == t {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func contains[T string | netip.Prefix](ts []T, t T) bool {
|
||||
for _, v := range ts {
|
||||
if reflect.DeepEqual(v, t) {
|
||||
|
|
Loading…
Reference in a new issue