Browse Source

use slices.Reverse from go1.21

tags/v2.12.0-rc1
Shivaram Lingamneni 8 months ago
parent
commit
b3abd0bf1d
4 changed files with 10 additions and 16 deletions
  1. 3
    2
      irc/history/history.go
  2. 4
    5
      irc/history/targets.go
  3. 3
    2
      irc/mysql/history.go
  4. 0
    7
      irc/utils/types.go

+ 3
- 2
irc/history/history.go View File

@@ -4,6 +4,7 @@
4 4
 package history
5 5
 
6 6
 import (
7
+	"slices"
7 8
 	"sync"
8 9
 	"time"
9 10
 
@@ -155,7 +156,7 @@ func (list *Buffer) betweenHelper(start, end Selector, cutoff time.Time, pred Pr
155 156
 
156 157
 	defer func() {
157 158
 		if !ascending {
158
-			utils.ReverseSlice(results)
159
+			slices.Reverse(results)
159 160
 		}
160 161
 	}()
161 162
 
@@ -262,7 +263,7 @@ func (list *Buffer) listCorrespondents(start, end Selector, cutoff time.Time, li
262 263
 	}
263 264
 
264 265
 	if !ascending {
265
-		utils.ReverseSlice(results)
266
+		slices.Reverse(results)
266 267
 	}
267 268
 
268 269
 	return

+ 4
- 5
irc/history/targets.go View File

@@ -4,10 +4,9 @@
4 4
 package history
5 5
 
6 6
 import (
7
+	"slices"
7 8
 	"sort"
8 9
 	"time"
9
-
10
-	"github.com/ergochat/ergo/irc/utils"
11 10
 )
12 11
 
13 12
 type TargetListing struct {
@@ -35,8 +34,8 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
35 34
 	results = make([]TargetListing, 0, prealloc)
36 35
 
37 36
 	if !ascending {
38
-		utils.ReverseSlice(base)
39
-		utils.ReverseSlice(extra)
37
+		slices.Reverse(base)
38
+		slices.Reverse(extra)
40 39
 	}
41 40
 
42 41
 	for len(results) < limit {
@@ -66,7 +65,7 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
66 65
 	}
67 66
 
68 67
 	if !ascending {
69
-		utils.ReverseSlice(results)
68
+		slices.Reverse(results)
70 69
 	}
71 70
 	return
72 71
 }

+ 3
- 2
irc/mysql/history.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"fmt"
12 12
 	"io"
13 13
 	"runtime/debug"
14
+	"slices"
14 15
 	"strings"
15 16
 	"sync"
16 17
 	"sync/atomic"
@@ -917,7 +918,7 @@ func (mysql *MySQL) betweenTimestamps(ctx context.Context, target, correspondent
917 918
 
918 919
 	results, err = mysql.selectItems(ctx, queryBuf.String(), args...)
919 920
 	if err == nil && !ascending {
920
-		utils.ReverseSlice(results)
921
+		slices.Reverse(results)
921 922
 	}
922 923
 	return
923 924
 }
@@ -965,7 +966,7 @@ func (mysql *MySQL) listCorrespondentsInternal(ctx context.Context, target strin
965 966
 	}
966 967
 
967 968
 	if !ascending {
968
-		utils.ReverseSlice(results)
969
+		slices.Reverse(results)
969 970
 	}
970 971
 
971 972
 	return

+ 0
- 7
irc/utils/types.go View File

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

Loading…
Cancel
Save