Kaynağa Gözat

use genericized slice-reversing function

tags/v2.10.0-rc1
Shivaram Lingamneni 2 yıl önce
ebeveyn
işleme
2df5fb1956
3 değiştirilmiş dosya ile 11 ekleme ve 9 silme
  1. 3
    8
      irc/history/history.go
  2. 1
    1
      irc/mysql/history.go
  3. 7
    0
      irc/utils/types.go

+ 3
- 8
irc/history/history.go Dosyayı Görüntüle

@@ -4,9 +4,10 @@
4 4
 package history
5 5
 
6 6
 import (
7
-	"github.com/ergochat/ergo/irc/utils"
8 7
 	"sync"
9 8
 	"time"
9
+
10
+	"github.com/ergochat/ergo/irc/utils"
10 11
 )
11 12
 
12 13
 type ItemType uint
@@ -55,12 +56,6 @@ func (item *Item) HasMsgid(msgid string) bool {
55 56
 
56 57
 type Predicate func(item *Item) (matches bool)
57 58
 
58
-func Reverse(results []Item) {
59
-	for i, j := 0, len(results)-1; i < j; i, j = i+1, j-1 {
60
-		results[i], results[j] = results[j], results[i]
61
-	}
62
-}
63
-
64 59
 // Buffer is a ring buffer holding message/event history for a channel or user
65 60
 type Buffer struct {
66 61
 	sync.RWMutex
@@ -160,7 +155,7 @@ func (list *Buffer) betweenHelper(start, end Selector, cutoff time.Time, pred Pr
160 155
 
161 156
 	defer func() {
162 157
 		if !ascending {
163
-			Reverse(results)
158
+			utils.ReverseSlice(results)
164 159
 		}
165 160
 	}()
166 161
 

+ 1
- 1
irc/mysql/history.go Dosyayı Görüntüle

@@ -916,7 +916,7 @@ func (mysql *MySQL) betweenTimestamps(ctx context.Context, target, correspondent
916 916
 
917 917
 	results, err = mysql.selectItems(ctx, queryBuf.String(), args...)
918 918
 	if err == nil && !ascending {
919
-		history.Reverse(results)
919
+		utils.ReverseSlice(results)
920 920
 	}
921 921
 	return
922 922
 }

+ 7
- 0
irc/utils/types.go Dosyayı Görüntüle

@@ -27,3 +27,10 @@ func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
27 27
 	}
28 28
 	return
29 29
 }
30
+
31
+// reverse the order of a slice in place
32
+func ReverseSlice[T any](results []T) {
33
+	for i, j := 0, len(results)-1; i < j; i, j = i+1, j-1 {
34
+		results[i], results[j] = results[j], results[i]
35
+	}
36
+}

Loading…
İptal
Kaydet