all: use new Go 1.23 slices.Sorted more

Updates #12912

Change-Id: If1294e5bc7b5d3cf0067535ae10db75e8b988d8b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/13380/head
Brad Fitzpatrick 3 months ago committed by Brad Fitzpatrick
parent fd6686d81a
commit 3d401c11fa

@ -19,7 +19,6 @@ import (
"sync" "sync"
"time" "time"
xmaps "golang.org/x/exp/maps"
"tailscale.com/control/controlknobs" "tailscale.com/control/controlknobs"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
@ -313,10 +312,8 @@ func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) {
} }
} }
if packetFilterChanged { if packetFilterChanged {
keys := xmaps.Keys(ms.namedPacketFilters)
sort.Strings(keys)
var concat []tailcfg.FilterRule var concat []tailcfg.FilterRule
for _, v := range keys { for _, v := range slices.Sorted(maps.Keys(ms.namedPacketFilters)) {
concat = ms.namedPacketFilters[v].AppendTo(concat) concat = ms.namedPacketFilters[v].AppendTo(concat)
} }
ms.lastPacketFilterRules = views.SliceOf(concat) ms.lastPacketFilterRules = views.SliceOf(concat)

@ -20,10 +20,11 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -76,12 +77,7 @@ func LogCurrent(logf logf) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
list := make([]string, 0, len(set)) for _, k := range slices.Sorted(maps.Keys(set)) {
for k := range set {
list = append(list, k)
}
sort.Strings(list)
for _, k := range list {
logf("envknob: %s=%q", k, set[k]) logf("envknob: %s=%q", k, set[k])
} }
} }

@ -7,12 +7,12 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"maps"
"net" "net"
"net/http" "net/http"
"net/netip" "net/netip"
"reflect" "reflect"
"slices" "slices"
"sort"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
@ -593,13 +593,7 @@ func TestMakeProbePlan(t *testing.T) {
func (plan probePlan) String() string { func (plan probePlan) String() string {
var sb strings.Builder var sb strings.Builder
keys := []string{} for _, key := range slices.Sorted(maps.Keys(plan)) {
for k := range plan {
keys = append(keys, k)
}
sort.Strings(keys)
for _, key := range keys {
fmt.Fprintf(&sb, "[%s]", key) fmt.Fprintf(&sb, "[%s]", key)
pv := plan[key] pv := plan[key]
for _, p := range pv { for _, p := range pv {

@ -7,11 +7,12 @@ import (
"bufio" "bufio"
"context" "context"
"fmt" "fmt"
"maps"
"net" "net"
"net/netip" "net/netip"
"reflect" "reflect"
"runtime" "runtime"
"sort" "slices"
"sync" "sync"
"time" "time"
"unsafe" "unsafe"
@ -907,12 +908,7 @@ func (c *Conn) foreachActiveDerpSortedLocked(fn func(regionID int, ad activeDerp
} }
return return
} }
ids := make([]int, 0, len(c.activeDerp)) for _, id := range slices.Sorted(maps.Keys(c.activeDerp)) {
for id := range c.activeDerp {
ids = append(ids, id)
}
sort.Ints(ids)
for _, id := range ids {
fn(id, c.activeDerp[id]) fn(id, c.activeDerp[id])
} }
} }

Loading…
Cancel
Save