forked from quic-go/quic-go
use the slices package to simply QUIC version comparisons (#5130)
No functional change expected.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user