diff --git a/helpers/general.go b/helpers/general.go index 5c3af9712..a9b0c0cd1 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -20,6 +20,7 @@ import ( "net" "os" "path/filepath" + "slices" "sort" "strings" "unicode" @@ -228,17 +229,7 @@ func compareStringSlices(a, b []string) bool { return false } - if len(a) != len(b) { - return false - } - - for i := range a { - if a[i] != b[i] { - return false - } - } - - return true + return slices.Equal(a, b) } // SliceToLower goes through the source slice and lowers all values. diff --git a/navigation/menu_cache.go b/navigation/menu_cache.go index 065781780..5723d4810 100644 --- a/navigation/menu_cache.go +++ b/navigation/menu_cache.go @@ -28,7 +28,7 @@ func (entry menuCacheEntry) matches(menuList []Menu) bool { return false } for i, m := range menuList { - if !menuEqual(m, entry.in[i]) { + if !slices.Equal(m, entry.in[i]) { return false } } @@ -46,21 +46,6 @@ type menuCache struct { m map[string][]menuCacheEntry } -// menuEqual checks if two menus are equal. -func menuEqual(m1, m2 Menu) bool { - if len(m1) != len(m2) { - return false - } - - for i := range m1 { - if m1[i] != m2[i] { - return false - } - } - - return true -} - // get retrieves a menu from the cache based on the provided key and menuLists. // If the menu is not found, it applies the provided function and caches the result. func (c *menuCache) get(key string, apply func(m Menu), menuLists ...Menu) (Menu, bool) { diff --git a/navigation/menu_cache_test.go b/navigation/menu_cache_test.go index 8fa17ffc3..a1f56b416 100644 --- a/navigation/menu_cache_test.go +++ b/navigation/menu_cache_test.go @@ -14,6 +14,7 @@ package navigation import ( + "slices" "sync" "sync/atomic" "testing" @@ -64,8 +65,8 @@ func TestMenuCache(t *testing.T) { l1.Unlock() m2, c2 := c1.get("k1", nil, m) c.Assert(c2, qt.Equals, true) - c.Assert(menuEqual(m, m2), qt.Equals, true) - c.Assert(menuEqual(m, menu), qt.Equals, true) + c.Assert(slices.Equal(m, m2), qt.Equals, true) + c.Assert(slices.Equal(m, menu), qt.Equals, true) c.Assert(m, qt.Not(qt.IsNil)) l2.Lock()