all: Use slices.Equal · gohugoio/hugo@ecdef2b (original) (raw)

Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import (
20 20 "net"
21 21 "os"
22 22 "path/filepath"
23 +"slices"
23 24 "sort"
24 25 "strings"
25 26 "unicode"
@@ -228,17 +229,7 @@ func compareStringSlices(a, b []string) bool {
228 229 return false
229 230 }
230 231
231 -if len(a) != len(b) {
232 -return false
233 - }
234 -
235 -for i := range a {
236 -if a[i] != b[i] {
237 -return false
238 - }
239 - }
240 -
241 -return true
232 +return slices.Equal(a, b)
242 233 }
243 234
244 235 // SliceToLower goes through the source slice and lowers all values.
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ func (entry menuCacheEntry) matches(menuList []Menu) bool {
28 28 return false
29 29 }
30 30 for i, m := range menuList {
31 -if !menuEqual(m, entry.in[i]) {
31 +if !slices.Equal(m, entry.in[i]) {
32 32 return false
33 33 }
34 34 }
@@ -46,21 +46,6 @@ type menuCache struct {
46 46 m map[string][]menuCacheEntry
47 47 }
48 48
49 -// menuEqual checks if two menus are equal.
50 -func menuEqual(m1, m2 Menu) bool {
51 -if len(m1) != len(m2) {
52 -return false
53 - }
54 -
55 -for i := range m1 {
56 -if m1[i] != m2[i] {
57 -return false
58 - }
59 - }
60 -
61 -return true
62 -}
63 -
64 49 // get retrieves a menu from the cache based on the provided key and menuLists.
65 50 // If the menu is not found, it applies the provided function and caches the result.
66 51 func (c *menuCache) get(key string, apply func(m Menu), menuLists ...Menu) (Menu, bool) {
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
14 14 package navigation
15 15
16 16 import (
17 +"slices"
17 18 "sync"
18 19 "sync/atomic"
19 20 "testing"
@@ -64,8 +65,8 @@ func TestMenuCache(t *testing.T) {
64 65 l1.Unlock()
65 66 m2, c2 := c1.get("k1", nil, m)
66 67 c.Assert(c2, qt.Equals, true)
67 -c.Assert(menuEqual(m, m2), qt.Equals, true)
68 -c.Assert(menuEqual(m, menu), qt.Equals, true)
68 +c.Assert(slices.Equal(m, m2), qt.Equals, true)
69 +c.Assert(slices.Equal(m, menu), qt.Equals, true)
69 70 c.Assert(m, qt.Not(qt.IsNil))
70 71
71 72 l2.Lock()