chore: use cmp in go 1.21
Co-authored-by: H1JK <hell0jack@protonmail.com>
This commit is contained in:
parent
c3d72f6883
commit
fa49fd7ba2
5 changed files with 34 additions and 20 deletions
|
@ -1,5 +1,4 @@
|
|||
//go:build linux || windows
|
||||
// +build linux windows
|
||||
//go:build linux || windows || darwin
|
||||
|
||||
package pmtud_fix
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//go:build !linux && !windows
|
||||
// +build !linux,!windows
|
||||
//go:build !linux && !windows && !darwin
|
||||
|
||||
package pmtud_fix
|
||||
|
||||
|
|
|
@ -3,27 +3,11 @@ package congestion
|
|||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
// InfDuration is a duration of infinite length
|
||||
const InfDuration = time.Duration(math.MaxInt64)
|
||||
|
||||
func Max[T constraints.Ordered](a, b T) T {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func Min[T constraints.Ordered](a, b T) T {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// MinNonZeroDuration return the minimum duration that's not zero.
|
||||
func MinNonZeroDuration(a, b time.Duration) time.Duration {
|
||||
if a == 0 {
|
||||
|
|
19
transport/tuic/congestion/minmax_go120.go
Normal file
19
transport/tuic/congestion/minmax_go120.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
//go:build !go1.21
|
||||
|
||||
package congestion
|
||||
|
||||
import "golang.org/x/exp/constraints"
|
||||
|
||||
func Max[T constraints.Ordered](a, b T) T {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func Min[T constraints.Ordered](a, b T) T {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
13
transport/tuic/congestion/minmax_go121.go
Normal file
13
transport/tuic/congestion/minmax_go121.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
//go:build go1.21
|
||||
|
||||
package congestion
|
||||
|
||||
import "cmp"
|
||||
|
||||
func Max[T cmp.Ordered](a, b T) T {
|
||||
return max(a, b)
|
||||
}
|
||||
|
||||
func Min[T cmp.Ordered](a, b T) T {
|
||||
return min(a, b)
|
||||
}
|
Loading…
Reference in a new issue