3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 11:59:40 +01:00

remove history.ReverseCorrespondents in favor of generics

This commit is contained in:
Shivaram Lingamneni 2022-05-03 02:45:36 -04:00
parent 66bf6244f3
commit c87dead39b
3 changed files with 7 additions and 12 deletions

View File

@ -262,7 +262,7 @@ func (list *Buffer) listCorrespondents(start, end Selector, cutoff time.Time, li
} }
if !ascending { if !ascending {
ReverseCorrespondents(results) utils.ReverseSlice(results)
} }
return return

View File

@ -6,6 +6,8 @@ package history
import ( import (
"sort" "sort"
"time" "time"
"github.com/ergochat/ergo/irc/utils"
) )
type TargetListing struct { type TargetListing struct {
@ -33,8 +35,8 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
results = make([]TargetListing, 0, prealloc) results = make([]TargetListing, 0, prealloc)
if !ascending { if !ascending {
ReverseCorrespondents(base) utils.ReverseSlice(base)
ReverseCorrespondents(extra) utils.ReverseSlice(extra)
} }
for len(results) < limit { for len(results) < limit {
@ -64,18 +66,11 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
} }
if !ascending { if !ascending {
ReverseCorrespondents(results) utils.ReverseSlice(results)
} }
return return
} }
func ReverseCorrespondents(results []TargetListing) {
// lol, generics when?
for i, j := 0, len(results)-1; i < j; i, j = i+1, j-1 {
results[i], results[j] = results[j], results[i]
}
}
func SortCorrespondents(list []TargetListing) { func SortCorrespondents(list []TargetListing) {
sort.Slice(list, func(i, j int) bool { sort.Slice(list, func(i, j int) bool {
return list[i].Time.Before(list[j].Time) return list[i].Time.Before(list[j].Time)

View File

@ -964,7 +964,7 @@ func (mysql *MySQL) listCorrespondentsInternal(ctx context.Context, target strin
} }
if !ascending { if !ascending {
history.ReverseCorrespondents(results) utils.ReverseSlice(results)
} }
return return