reflect.DeepEqual is a value copy that causes golang to continuously allocate memory

This commit is contained in:
Allen 2023-01-03 15:59:48 +08:00 committed by Kristoffer Dalby
parent 893b0de8fa
commit 4e2c4f92d3
2 changed files with 11 additions and 1 deletions

View File

@ -155,7 +155,7 @@ func (machine *Machine) isOnline() bool {
func containsAddresses(inputs []string, addrs []string) bool { func containsAddresses(inputs []string, addrs []string) bool {
for _, addr := range addrs { for _, addr := range addrs {
if contains(inputs, addr) { if containsStr(inputs, addr) {
return true return true
} }
} }

View File

@ -269,6 +269,16 @@ func stringToIPPrefix(prefixes []string) ([]netip.Prefix, error) {
return result, nil 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 { func contains[T string | netip.Prefix](ts []T, t T) bool {
for _, v := range ts { for _, v := range ts {
if reflect.DeepEqual(v, t) { if reflect.DeepEqual(v, t) {