From fa49fd7ba2efbae8cb9b00bf5cf786ea940037d2 Mon Sep 17 00:00:00 2001 From: Larvan2 <78135608+larvan2@users.noreply.github.com> Date: Fri, 15 Sep 2023 23:15:05 +0800 Subject: [PATCH] chore: use cmp in go 1.21 Co-authored-by: H1JK --- transport/hysteria/pmtud_fix/avail.go | 3 +-- transport/hysteria/pmtud_fix/unavail.go | 3 +-- transport/tuic/congestion/minmax.go | 16 ---------------- transport/tuic/congestion/minmax_go120.go | 19 +++++++++++++++++++ transport/tuic/congestion/minmax_go121.go | 13 +++++++++++++ 5 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 transport/tuic/congestion/minmax_go120.go create mode 100644 transport/tuic/congestion/minmax_go121.go diff --git a/transport/hysteria/pmtud_fix/avail.go b/transport/hysteria/pmtud_fix/avail.go index 2f2bce83..af248f5c 100644 --- a/transport/hysteria/pmtud_fix/avail.go +++ b/transport/hysteria/pmtud_fix/avail.go @@ -1,5 +1,4 @@ -//go:build linux || windows -// +build linux windows +//go:build linux || windows || darwin package pmtud_fix diff --git a/transport/hysteria/pmtud_fix/unavail.go b/transport/hysteria/pmtud_fix/unavail.go index 0eeb83df..35b849d2 100644 --- a/transport/hysteria/pmtud_fix/unavail.go +++ b/transport/hysteria/pmtud_fix/unavail.go @@ -1,5 +1,4 @@ -//go:build !linux && !windows -// +build !linux,!windows +//go:build !linux && !windows && !darwin package pmtud_fix diff --git a/transport/tuic/congestion/minmax.go b/transport/tuic/congestion/minmax.go index ed75072e..0a8f4ad4 100644 --- a/transport/tuic/congestion/minmax.go +++ b/transport/tuic/congestion/minmax.go @@ -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 { diff --git a/transport/tuic/congestion/minmax_go120.go b/transport/tuic/congestion/minmax_go120.go new file mode 100644 index 00000000..1266edbc --- /dev/null +++ b/transport/tuic/congestion/minmax_go120.go @@ -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 +} diff --git a/transport/tuic/congestion/minmax_go121.go b/transport/tuic/congestion/minmax_go121.go new file mode 100644 index 00000000..65b06726 --- /dev/null +++ b/transport/tuic/congestion/minmax_go121.go @@ -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) +}