From 6180da00e1d310b79a0a01770c3847304bb2a94e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 17 Sep 2024 01:59:54 -0700
Subject: [PATCH] Skip a lock/unlock when logging known categories
---
src/SDL_log.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/SDL_log.c b/src/SDL_log.c
index 56780e7e0c72e..dd274bfaff4ef 100644
--- a/src/SDL_log.c
+++ b/src/SDL_log.c
@@ -239,6 +239,14 @@ SDL_LogPriority SDL_GetLogPriority(int category)
SDL_CheckInitLog();
+ // Bypass the lock for known categories
+ // Technically if the priority was set on a different CPU the value might not
+ // be visible on this CPU for a while, but in practice it's fast enough that
+ // this performance improvement is worthwhile.
+ if (category >= 0 && category < SDL_arraysize(SDL_log_priorities)) {
+ return SDL_log_priorities[category];
+ }
+
SDL_LockMutex(SDL_log_lock);
{
if (category >= 0 && category < SDL_arraysize(SDL_log_priorities)) {