3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 05:19:25 +01:00

Merge pull request #1948 from slingamn/reverse_again

remove history.ReverseCorrespondents in favor of generics
This commit is contained in:
Shivaram Lingamneni 2022-05-03 12:42:23 -04:00 committed by GitHub
commit dea2e7961a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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