소스 검색

use slices.Reverse from go1.21

tags/v2.12.0-rc1
Shivaram Lingamneni 9 달 전
부모
커밋
b3abd0bf1d
4개의 변경된 파일10개의 추가작업 그리고 16개의 파일을 삭제
  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 파일 보기

4
 package history
4
 package history
5
 
5
 
6
 import (
6
 import (
7
+	"slices"
7
 	"sync"
8
 	"sync"
8
 	"time"
9
 	"time"
9
 
10
 
155
 
156
 
156
 	defer func() {
157
 	defer func() {
157
 		if !ascending {
158
 		if !ascending {
158
-			utils.ReverseSlice(results)
159
+			slices.Reverse(results)
159
 		}
160
 		}
160
 	}()
161
 	}()
161
 
162
 
262
 	}
263
 	}
263
 
264
 
264
 	if !ascending {
265
 	if !ascending {
265
-		utils.ReverseSlice(results)
266
+		slices.Reverse(results)
266
 	}
267
 	}
267
 
268
 
268
 	return
269
 	return

+ 4
- 5
irc/history/targets.go 파일 보기

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

+ 3
- 2
irc/mysql/history.go 파일 보기

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

+ 0
- 7
irc/utils/types.go 파일 보기

36
 	return
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
 func SliceContains[T comparable](slice []T, elem T) (result bool) {
39
 func SliceContains[T comparable](slice []T, elem T) (result bool) {
47
 	for _, t := range slice {
40
 	for _, t := range slice {
48
 		if elem == t {
41
 		if elem == t {

Loading…
취소
저장