From 523588a0aa677c65595543ebef122b7b0d42e3f9 Mon Sep 17 00:00:00 2001 From: phuslu Date: Mon, 22 Apr 2024 20:44:01 +0800 Subject: [PATCH] avoid atomic level overhead for amd64 --- logger.go | 4 ---- logger_arch_amd64.go | 9 +++++++++ logger_arch_others.go | 12 ++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 logger_arch_amd64.go create mode 100644 logger_arch_others.go diff --git a/logger.go b/logger.go index 87e2ddf6..e9062094 100644 --- a/logger.go +++ b/logger.go @@ -448,10 +448,6 @@ var timeOffset, timeZone = func() (int64, string) { return int64(n), s }() -func (l *Logger) silent(level Level) bool { - return uint32(level) < atomic.LoadUint32((*uint32)(&l.Level)) -} - func (l *Logger) header(level Level) *Entry { e := epool.Get().(*Entry) e.buf = e.buf[:0] diff --git a/logger_arch_amd64.go b/logger_arch_amd64.go new file mode 100644 index 00000000..c53c0ccc --- /dev/null +++ b/logger_arch_amd64.go @@ -0,0 +1,9 @@ +//go:build amd64 +// +build amd64 + +package log + +//gcassert:inline +func (l *Logger) silent(level Level) bool { + return level < l.Level +} diff --git a/logger_arch_others.go b/logger_arch_others.go new file mode 100644 index 00000000..191f95c2 --- /dev/null +++ b/logger_arch_others.go @@ -0,0 +1,12 @@ +//go:build !amd64 +// +build !amd64 + +package log + +import ( + "sync/atomic" +) + +func (l *Logger) silent(level Level) bool { + return uint32(level) < atomic.LoadUint32((*uint32)(&l.Level)) +}