From 10697b85d3d01e9941f79b0b2b68cb9dd964f3f3 Mon Sep 17 00:00:00 2001 From: phuslu Date: Sun, 10 Mar 2024 11:38:53 +0800 Subject: [PATCH] use cheaprandn as Fastrandn for go1.22 --- logger.go | 6 ------ logger_go1.18.go | 14 ++++++++++++++ logger_go1.22.go | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 logger_go1.18.go create mode 100644 logger_go1.22.go diff --git a/logger.go b/logger.go index 45d8897e..f5d128a8 100644 --- a/logger.go +++ b/logger.go @@ -2135,9 +2135,3 @@ func absClock(abs uint64) (hour, min, sec int) //go:noescape //go:linkname callers runtime.callers func callers(skip int, pcbuf []uintptr) int - -// Fastrandn returns a pseudorandom uint32 in [0,n). -// -//go:noescape -//go:linkname Fastrandn runtime.fastrandn -func Fastrandn(x uint32) uint32 diff --git a/logger_go1.18.go b/logger_go1.18.go new file mode 100644 index 00000000..e653d509 --- /dev/null +++ b/logger_go1.18.go @@ -0,0 +1,14 @@ +//go:build go1.18 && !go1.22 +// +build go1.18,!go1.22 + +package log + +import ( + _ "unsafe" +) + +// Fastrandn returns a pseudorandom uint32 in [0,n). +// +//go:noescape +//go:linkname Fastrandn runtime.fastrandn +func Fastrandn(x uint32) uint32 diff --git a/logger_go1.22.go b/logger_go1.22.go new file mode 100644 index 00000000..5565d94f --- /dev/null +++ b/logger_go1.22.go @@ -0,0 +1,14 @@ +//go:build go1.22 +// +build go1.22 + +package log + +import ( + _ "unsafe" +) + +// Fastrandn returns a pseudorandom uint32 in [0,n). +// +//go:noescape +//go:linkname Fastrandn runtime.cheaprandn +func Fastrandn(x uint32) uint32