3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

use slices.Reverse from go1.21

This commit is contained in:
Shivaram Lingamneni 2023-08-15 20:45:00 -04:00
parent cc873efd0f
commit b3abd0bf1d
4 changed files with 10 additions and 16 deletions

View File

@ -4,6 +4,7 @@
package history
import (
"slices"
"sync"
"time"
@ -155,7 +156,7 @@ func (list *Buffer) betweenHelper(start, end Selector, cutoff time.Time, pred Pr
defer func() {
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
}()
@ -262,7 +263,7 @@ func (list *Buffer) listCorrespondents(start, end Selector, cutoff time.Time, li
}
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return

View File

@ -4,10 +4,9 @@
package history
import (
"slices"
"sort"
"time"
"github.com/ergochat/ergo/irc/utils"
)
type TargetListing struct {
@ -35,8 +34,8 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
results = make([]TargetListing, 0, prealloc)
if !ascending {
utils.ReverseSlice(base)
utils.ReverseSlice(extra)
slices.Reverse(base)
slices.Reverse(extra)
}
for len(results) < limit {
@ -66,7 +65,7 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
}
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return
}

View File

@ -11,6 +11,7 @@ import (
"fmt"
"io"
"runtime/debug"
"slices"
"strings"
"sync"
"sync/atomic"
@ -917,7 +918,7 @@ func (mysql *MySQL) betweenTimestamps(ctx context.Context, target, correspondent
results, err = mysql.selectItems(ctx, queryBuf.String(), args...)
if err == nil && !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return
}
@ -965,7 +966,7 @@ func (mysql *MySQL) listCorrespondentsInternal(ctx context.Context, target strin
}
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return

View File

@ -36,13 +36,6 @@ func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
return
}
// reverse the order of a slice in place
func ReverseSlice[T any](results []T) {
for i, j := 0, len(results)-1; i < j; i, j = i+1, j-1 {
results[i], results[j] = results[j], results[i]
}
}
func SliceContains[T comparable](slice []T, elem T) (result bool) {
for _, t := range slice {
if elem == t {