]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
all: Use slices.Equal
authorminxinyi <minxinyi6@outlook.com>
Sun, 24 Aug 2025 18:35:18 +0000 (02:35 +0800)
committerGitHub <noreply@github.com>
Sun, 24 Aug 2025 18:35:18 +0000 (20:35 +0200)
helpers/general.go
navigation/menu_cache.go
navigation/menu_cache_test.go

index 5c3af97128cc8c9455973137c2a2cdeed021d421..a9b0c0cd1ac5d069b8eaca91691c627f3f7ef176 100644 (file)
@@ -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.
index 065781780953f86d6ac622daf4c419e6d2ec2ce1..5723d4810784eb0e979742d1a4597ef5d8b5f61e 100644 (file)
@@ -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) {
index 8fa17ffc37fd43597eee4b08ca8ae03b07828d37..a1f56b416205dd2bc40357e7dd8831ef84084e41 100644 (file)
@@ -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()