all: Use some Go 1.21 features (#9409)
This commit is contained in:
+1
-1
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -19,7 +20,6 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/rand"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
+1
-1
@@ -18,6 +18,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -46,7 +47,6 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/tlsutil"
|
||||
"github.com/syncthing/syncthing/lib/ur"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/rand"
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type tokenManager struct {
|
||||
|
||||
@@ -22,14 +22,12 @@ import (
|
||||
"math"
|
||||
"net"
|
||||
"net/url"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
stdsync "sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/connections/registry"
|
||||
@@ -1468,20 +1466,3 @@ func newConnectionID(t0, t1 int64) string {
|
||||
// from the random. We want the timestamp part deterministic.
|
||||
return enc.EncodeToString(buf[:8]) + enc.EncodeToString(buf[8:])
|
||||
}
|
||||
|
||||
// temporary implementations of min and max, to be removed once we can use
|
||||
// Go 1.21 builtins. :)
|
||||
|
||||
func min[T constraints.Ordered](a, b T) T {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func max[T constraints.Ordered](a, b T) T {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -10,10 +10,9 @@ package locations
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func TestUnixConfigDir(t *testing.T) {
|
||||
|
||||
@@ -12,11 +12,10 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// This package uses stdlib sync as it may be used to debug syncthing/lib/sync
|
||||
|
||||
@@ -9,11 +9,11 @@ package model
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func TestJobQueue(t *testing.T) {
|
||||
|
||||
+3
-12
@@ -12,6 +12,7 @@ import (
|
||||
"hash/fnv"
|
||||
"math/rand"
|
||||
"net"
|
||||
"slices"
|
||||
stdsync "sync"
|
||||
"time"
|
||||
|
||||
@@ -411,21 +412,11 @@ func addrSetsEqual(a []Address, b []Address) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO: Rewrite this using slice.Contains once Go 1.21 is the minimum Go version.
|
||||
for _, aElem := range a {
|
||||
aElemFound := false
|
||||
for _, bElem := range b {
|
||||
if bElem.Equal(aElem) {
|
||||
aElemFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !aElemFound {
|
||||
// Found element in a that is not in b.
|
||||
for _, v := range a {
|
||||
if !slices.ContainsFunc(b, v.Equal) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// b contains all elements of a and their lengths are equal, so the sets are equal.
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -43,13 +43,6 @@ func (v Vector) updateWithNow(id ShortID, now uint64) Vector {
|
||||
})}
|
||||
}
|
||||
|
||||
func max(a, b uint64) uint64 {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Merge returns the vector containing the maximum indexes from v and b. If it
|
||||
// is possible, the vector v is updated and returned. If it is not, a copy
|
||||
// will be created, updated and returned.
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
package sliceutil_test
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/sliceutil"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func TestRemoveAndZero(t *testing.T) {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
package versioner
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -88,7 +87,7 @@ func TestSimpleVersioningVersionCount(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if float64(len(n)) != math.Min(float64(i), 2) {
|
||||
if len(n) != min(i, 2) {
|
||||
t.Error("Wrong count")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user