diff --git a/internal/memoization/memoization.go b/internal/memoization/memoization.go index 46c347a..845c280 100644 --- a/internal/memoization/memoization.go +++ b/internal/memoization/memoization.go @@ -121,5 +121,5 @@ type HInt int // Hash is a method that returns the hash of the integer. func (h HInt) Hash() string { - return fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%d", h)))) + return fmt.Sprintf("%x", sha256.Sum256(fmt.Appendf(nil, "%d", h))) } diff --git a/internal/memoization/memoization_test.go b/internal/memoization/memoization_test.go index 7e21232..4d63b1d 100644 --- a/internal/memoization/memoization_test.go +++ b/internal/memoization/memoization_test.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "fmt" "os" + "slices" "testing" ) @@ -17,8 +18,8 @@ const ( type cacheAction struct { actionType actionType key HString - value interface{} - expectedValue interface{} + value any + expectedValue any } type testCase struct { @@ -121,7 +122,7 @@ func TestCache(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cache := NewMemoCache[HString, interface{}](tt.capacity) + cache := NewMemoCache[HString, any](tt.capacity) for _, action := range tt.actions { switch action.actionType { case set: @@ -174,7 +175,7 @@ func FuzzCache(f *testing.F) { // If the key is already in accessOrder, we remove it and append it again later for index, accessedKey := range accessOrder { if accessedKey == key { - accessOrder = append(accessOrder[:index], accessOrder[index+1:]...) + accessOrder = slices.Delete(accessOrder, index, index+1) break } } @@ -206,7 +207,7 @@ func FuzzCache(f *testing.F) { // If the key was accessed, move it to the end of the accessOrder to represent recent use for index, accessedKey := range accessOrder { if accessedKey == key { - accessOrder = append(accessOrder[:index], accessOrder[index+1:]...) + accessOrder = slices.Delete(accessOrder, index, index+1) accessOrder = append(accessOrder, key) break } diff --git a/internal/runeutil/runeutil.go b/internal/runeutil/runeutil.go index 6856cc8..3d5b288 100644 --- a/internal/runeutil/runeutil.go +++ b/internal/runeutil/runeutil.go @@ -61,7 +61,7 @@ func (s *sanitizer) Sanitize(runes []rune) []rune { // is smaller or equal to the input. copied := false - for src := 0; src < len(runes); src++ { + for src := range runes { r := runes[src] switch { case r == utf8.RuneError: diff --git a/paginator/paginator.go b/paginator/paginator.go index 7abe326..d5b786e 100644 --- a/paginator/paginator.go +++ b/paginator/paginator.go @@ -185,7 +185,7 @@ func (m Model) View() string { func (m Model) dotsView() string { var s string - for i := 0; i < m.TotalPages; i++ { + for i := range m.TotalPages { if i == m.Page { s += m.ActiveDot continue diff --git a/progress/progress.go b/progress/progress.go index c0bc6a6..dc933df 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -295,7 +295,7 @@ func (m Model) barView(b *strings.Builder, percent float64, textWidth int) { if m.useRamp { // Gradient fill - for i := 0; i < fw; i++ { + for i := range fw { if fw == 1 { // this is up for debate: in a gradient of width=1, should the // single character rendered be the first color, the last color diff --git a/viewport/viewport_test.go b/viewport/viewport_test.go index b64e9fd..bf504dd 100644 --- a/viewport/viewport_test.go +++ b/viewport/viewport_test.go @@ -374,7 +374,7 @@ func TestRightOverscroll(t *testing.T) { m := New(WithHeight(5), WithWidth(len(content)+1)) m.SetContent(content) - for i := 0; i < 10; i++ { + for range 10 { m.ScrollRight(m.horizontalStep) }