use the slices package to simply QUIC version comparisons (#5130)

No functional change expected.
This commit is contained in:
Marten Seemann
2025-05-09 12:24:45 +08:00
committed by GitHub
parent 1725cb0878
commit 8474eddd3a
2 changed files with 11 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"math"
mrand "math/rand/v2"
"slices"
"sync"
)
@@ -64,12 +65,7 @@ func (vn Version) toGQUICVersion() int {
// IsSupportedVersion returns true if the server supports this version
func IsSupportedVersion(supported []Version, v Version) bool {
for _, t := range supported {
if t == v {
return true
}
}
return false
return slices.Contains(supported, v)
}
// ChooseSupportedVersion finds the best version in the overlap of ours and theirs
@@ -78,10 +74,8 @@ func IsSupportedVersion(supported []Version, v Version) bool {
// The bool returned indicates if a matching version was found.
func ChooseSupportedVersion(ours, theirs []Version) (Version, bool) {
for _, ourVer := range ours {
for _, theirVer := range theirs {
if ourVer == theirVer {
return ourVer, true
}
if slices.Contains(theirs, ourVer) {
return ourVer, true
}
}
return 0, false