"strSliceContains" is replaced by "slices.Contains".
Replace "sort.Strings" with "slices.Sort" since it becomes a wrapper
of "slices.Sort" from Go 1.22.
"headerSorter" no longer has to implement "sort.Interface".
We use "slice.SortFunc" to sort kvs.
Change-Id: Ic29b4c3db147c16079575eca7ad6ff6c0f581188
GitHub-Last-Rev:
78221d5aa223a259a89860b672f39a34897df253
GitHub-Pull-Request: golang/go#66440
Reviewed-on: https://go-review.googlesource.com/c/go/+/573275
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
"net/http/internal/ascii"
"net/url"
"reflect"
- "sort"
+ "slices"
"strings"
"sync"
"sync/atomic"
ss = append(ss, c.Name+"="+c.Value)
}
}
- sort.Strings(ss) // Ensure deterministic headers
+ slices.Sort(ss) // Ensure deterministic headers
ireqhdr.Set("Cookie", strings.Join(ss, "; "))
}
}
"fmt"
"net"
"net/url"
- "sort"
+ "slices"
"sync"
"testing"
"time"
for key := range t.idleConn {
keys = append(keys, key.String())
}
- sort.Strings(keys)
+ slices.Sort(keys)
return
}
ret = append(ret, pc.conn.LocalAddr().String()+"/"+pc.conn.RemoteAddr().String())
}
}
- sort.Strings(ret)
+ slices.Sort(ret)
return ret
}
}
}
- sort.Strings(ret)
+ slices.Sort(ret)
return ret
}
"net/http/httptrace"
"net/http/internal/ascii"
"net/textproto"
- "sort"
+ "slices"
"strings"
"sync"
"time"
values []string
}
-// A headerSorter implements sort.Interface by sorting a []keyValues
-// by key. It's used as a pointer, so it can fit in a sort.Interface
-// interface value without allocation.
+// headerSorter contains a slice of keyValues sorted by keyValues.key.
type headerSorter struct {
kvs []keyValues
}
-func (s *headerSorter) Len() int { return len(s.kvs) }
-func (s *headerSorter) Swap(i, j int) { s.kvs[i], s.kvs[j] = s.kvs[j], s.kvs[i] }
-func (s *headerSorter) Less(i, j int) bool { return s.kvs[i].key < s.kvs[j].key }
-
var headerSorterPool = sync.Pool{
New: func() any { return new(headerSorter) },
}
}
}
hs.kvs = kvs
- sort.Sort(hs)
+ slices.SortFunc(hs.kvs, func(a, b keyValues) int { return strings.Compare(a.key, b.key) })
return kvs, hs
}
"net/http"
"os"
"runtime"
- "sort"
+ "slices"
"strings"
"testing"
"time"
}
gs = append(gs, stack)
}
- sort.Strings(gs)
+ slices.Sort(gs)
return
}
import (
"fmt"
"slices"
- "sort"
"strings"
"testing"
)
s = append(s, p.String())
}
}
- sort.Strings(s)
+ slices.Sort(s)
return s
}
}
return nil
})
- sort.Strings(s)
+ slices.Sort(s)
return slices.Compact(s)
}
import (
"fmt"
"io"
- "sort"
"strings"
"testing"
ms := map[string]bool{}
test.tree.matchingMethods(test.host, test.path, ms)
keys := mapKeys(ms)
- sort.Strings(keys)
+ slices.Sort(keys)
got := strings.Join(keys, ",")
if got != test.want {
t.Errorf("got %s, want %s", got, test.want)
keys = append(keys, k)
return true
})
- sort.Strings(keys)
+ slices.Sort(keys)
for _, k := range keys {
fmt.Fprintf(w, "%s%q:\n", indent, k)
urlpkg "net/url"
"path"
"runtime"
- "sort"
+ "slices"
"strconv"
"strings"
"sync"
// matchOrRedirect will try appending a trailing slash if there is no match.
mux.tree.matchingMethods(host, path+"/", ms)
methods := mapKeys(ms)
- sort.Strings(methods)
+ slices.Sort(methods)
return methods
}
// passed this tls.Config to tls.NewListener. And if they did,
// it's too late anyway to fix it. It would only be potentially racy.
// See Issue 15908.
- return strSliceContains(srv.TLSConfig.NextProtos, http2NextProtoTLS)
+ return slices.Contains(srv.TLSConfig.NextProtos, http2NextProtoTLS)
}
// ErrServerClosed is returned by the [Server.Serve], [ServeTLS], [ListenAndServe],
}
config := cloneTLSConfig(srv.TLSConfig)
- if !strSliceContains(config.NextProtos, "http/1.1") {
+ if !slices.Contains(config.NextProtos, "http/1.1") {
config.NextProtos = append(config.NextProtos, "http/1.1")
}
return
}
-func strSliceContains(ss []string, s string) bool {
- for _, v := range ss {
- if v == s {
- return true
- }
- }
- return false
-}
-
// tlsRecordHeaderLooksLikeHTTP reports whether a TLS record header
// looks like it might've been a misdirected plaintext HTTP request.
func tlsRecordHeaderLooksLikeHTTP(hdr [5]byte) bool {
"net/http/internal/ascii"
"net/textproto"
"reflect"
- "sort"
+ "slices"
"strconv"
"strings"
"sync"
keys = append(keys, k)
}
if len(keys) > 0 {
- sort.Strings(keys)
+ slices.Sort(keys)
// TODO: could do better allocation-wise here, but trailers are rare,
// so being lazy for now.
if _, err := io.WriteString(w, "Trailer: "+strings.Join(keys, ",")+"\r\n"); err != nil {