Skip to content

Commit 92a9648

Browse files
authored
Replace golang.org/x/exp/slices with stdlib slices (#6657)
The experimental functions in `golang.org/x/exp/slices` are now available in the standard library in Go 1.21. Reference: https://go.dev/doc/go1.21#slices Signed-off-by: Eng Zer Jun <[email protected]>
1 parent caf0a2f commit 92a9648

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ require (
8484
github.com/sercand/kuberesolver/v5 v5.1.1
8585
github.com/tjhop/slog-gokit v0.1.2
8686
go.opentelemetry.io/collector/pdata v1.24.0
87-
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
8887
google.golang.org/protobuf v1.36.4
8988
)
9089

@@ -242,6 +241,7 @@ require (
242241
go4.org/intern v0.0.0-20230525184215-6c62f75575cb // indirect
243242
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
244243
golang.org/x/crypto v0.35.0 // indirect
244+
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
245245
golang.org/x/mod v0.22.0 // indirect
246246
golang.org/x/oauth2 v0.25.0 // indirect
247247
golang.org/x/sys v0.30.0 // indirect

pkg/compactor/sharded_block_populator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"log/slog"
77
"maps"
8+
"slices"
89
"sync"
910
"time"
1011

@@ -16,7 +17,6 @@ import (
1617
"github.com/prometheus/prometheus/tsdb/chunkenc"
1718
"github.com/prometheus/prometheus/tsdb/chunks"
1819
tsdb_errors "github.com/prometheus/prometheus/tsdb/errors"
19-
"golang.org/x/exp/slices"
2020
"golang.org/x/sync/errgroup"
2121
)
2222

pkg/ring/lifecycler_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ package ring
33
import (
44
"context"
55
"fmt"
6-
"sort"
6+
"slices"
77
"testing"
88
"time"
99

1010
"github.com/go-kit/log"
1111
"github.com/pkg/errors"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
14-
"golang.org/x/exp/slices"
1514

1615
"github.com/cortexproject/cortex/pkg/ring/kv/consul"
1716
"github.com/cortexproject/cortex/pkg/util/flagext"
@@ -906,8 +905,8 @@ func TestTokenFileOnDisk(t *testing.T) {
906905
})
907906

908907
// Check for same tokens.
909-
sort.Slice(expTokens, func(i, j int) bool { return expTokens[i] < expTokens[j] })
910-
sort.Slice(actTokens, func(i, j int) bool { return actTokens[i] < actTokens[j] })
908+
slices.Sort(expTokens)
909+
slices.Sort(actTokens)
911910
for i := 0; i < 512; i++ {
912911
require.Equal(t, expTokens, actTokens)
913912
}
@@ -1088,8 +1087,8 @@ func TestTokenFileOnDisk_WithoutAutoJoinOnStartup(t *testing.T) {
10881087
})
10891088

10901089
// Check for same tokens.
1091-
sort.Slice(expTokens, func(i, j int) bool { return expTokens[i] < expTokens[j] })
1092-
sort.Slice(actTokens, func(i, j int) bool { return actTokens[i] < actTokens[j] })
1090+
slices.Sort(expTokens)
1091+
slices.Sort(actTokens)
10931092
for i := 0; i < 512; i++ {
10941093
require.Equal(t, expTokens, actTokens)
10951094
}

pkg/storage/tsdb/multilevel_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tsdb
33
import (
44
"context"
55
"errors"
6+
"slices"
67

78
"github.com/oklog/ulid"
89
"github.com/prometheus/client_golang/prometheus"
@@ -11,7 +12,6 @@ import (
1112
"github.com/prometheus/prometheus/storage"
1213
"github.com/thanos-io/thanos/pkg/cacheutil"
1314
storecache "github.com/thanos-io/thanos/pkg/store/cache"
14-
"golang.org/x/exp/slices"
1515
)
1616

1717
type multiLevelCache struct {

pkg/storage/tsdb/users_scanner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package tsdb
33
import (
44
"context"
55
"errors"
6+
"slices"
67
"testing"
78

89
"github.com/go-kit/log"
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
11-
"golang.org/x/exp/slices"
1212

1313
"github.com/cortexproject/cortex/pkg/storage/bucket"
1414
)

0 commit comments

Comments
 (0)