From c87dead39bbcd276f01299934b206324590b45c6 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 3 May 2022 02:45:36 -0400 Subject: [PATCH] remove history.ReverseCorrespondents in favor of generics --- irc/history/history.go | 2 +- irc/history/targets.go | 15 +++++---------- irc/mysql/history.go | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/irc/history/history.go b/irc/history/history.go index fda91c03..75d6298d 100644 --- a/irc/history/history.go +++ b/irc/history/history.go @@ -262,7 +262,7 @@ func (list *Buffer) listCorrespondents(start, end Selector, cutoff time.Time, li } if !ascending { - ReverseCorrespondents(results) + utils.ReverseSlice(results) } return diff --git a/irc/history/targets.go b/irc/history/targets.go index 39a0c209..39a8c635 100644 --- a/irc/history/targets.go +++ b/irc/history/targets.go @@ -6,6 +6,8 @@ package history import ( "sort" "time" + + "github.com/ergochat/ergo/irc/utils" ) type TargetListing struct { @@ -33,8 +35,8 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T results = make([]TargetListing, 0, prealloc) if !ascending { - ReverseCorrespondents(base) - ReverseCorrespondents(extra) + utils.ReverseSlice(base) + utils.ReverseSlice(extra) } for len(results) < limit { @@ -64,18 +66,11 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T } if !ascending { - ReverseCorrespondents(results) + utils.ReverseSlice(results) } 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) { sort.Slice(list, func(i, j int) bool { return list[i].Time.Before(list[j].Time) diff --git a/irc/mysql/history.go b/irc/mysql/history.go index dddef81e..9b69bae1 100644 --- a/irc/mysql/history.go +++ b/irc/mysql/history.go @@ -964,7 +964,7 @@ func (mysql *MySQL) listCorrespondentsInternal(ctx context.Context, target strin } if !ascending { - history.ReverseCorrespondents(results) + utils.ReverseSlice(results) } return