From 4e2c4f92d36914398a4b09905717d0a1fb427843 Mon Sep 17 00:00:00 2001 From: Allen <979347228@qq.com> Date: Tue, 3 Jan 2023 15:59:48 +0800 Subject: [PATCH] reflect.DeepEqual is a value copy that causes golang to continuously allocate memory --- machine.go | 2 +- utils.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/machine.go b/machine.go index cae5c68..3ddf471 100644 --- a/machine.go +++ b/machine.go @@ -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 } } diff --git a/utils.go b/utils.go index 8bdb2b3..5d7f487 100644 --- a/utils.go +++ b/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) {