From 8f83ac11c36f231c7c81c4783b28d290b1d3567e Mon Sep 17 00:00:00 2001 From: jishudashu <979260390@qq.com> Date: Thu, 24 Jul 2025 12:39:59 +0800 Subject: [PATCH] refactor: use slices.Equal to simplify code Signed-off-by: jishudashu <979260390@qq.com> --- internal/addrs/module.go | 11 ++--------- internal/addrs/module_instance.go | 12 ++---------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/internal/addrs/module.go b/internal/addrs/module.go index 4d71034d1986..2ae264144805 100644 --- a/internal/addrs/module.go +++ b/internal/addrs/module.go @@ -4,6 +4,7 @@ package addrs import ( + "slices" "strings" "github.com/hashicorp/hcl/v2" @@ -58,15 +59,7 @@ func (m Module) String() string { } func (m Module) Equal(other Module) bool { - if len(m) != len(other) { - return false - } - for i := range m { - if m[i] != other[i] { - return false - } - } - return true + return slices.Equal(m, other) } type moduleKey string diff --git a/internal/addrs/module_instance.go b/internal/addrs/module_instance.go index 5ebce0ab95d9..9e8e85e64b26 100644 --- a/internal/addrs/module_instance.go +++ b/internal/addrs/module_instance.go @@ -5,6 +5,7 @@ package addrs import ( "fmt" + "slices" "strings" "github.com/hashicorp/hcl/v2" @@ -305,16 +306,7 @@ func (mk moduleInstanceKey) uniqueKeySigil() {} // Equal returns true if the receiver and the given other value // contains the exact same parts. func (m ModuleInstance) Equal(o ModuleInstance) bool { - if len(m) != len(o) { - return false - } - - for i := range m { - if m[i] != o[i] { - return false - } - } - return true + return slices.Equal(m, o) } // Less returns true if the receiver should sort before the given other value