SDL: Reduce strcmp() calls in hashtable lookup

From 56fc4b790c4f1f9a6327b15a832db514667cb7d8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 14 Sep 2024 11:46:40 -0700
Subject: [PATCH] Reduce strcmp() calls in hashtable lookup

---
 src/SDL_hashtable.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/SDL_hashtable.c b/src/SDL_hashtable.c
index d233ce5949c2b..feaa08f52af2b 100644
--- a/src/SDL_hashtable.c
+++ b/src/SDL_hashtable.c
@@ -294,12 +294,17 @@ Uint32 SDL_HashString(const void *key, void *data)
 
 bool SDL_KeyMatchString(const void *a, const void *b, void *data)
 {
+    const char *a_string = (const char *)a;
+    const char *b_string = (const char *)b;
+
     if (a == b) {
         return true;  // same pointer, must match.
     } else if (!a || !b) {
         return false;  // one pointer is NULL (and first test shows they aren't the same pointer), must not match.
+    } else if (a_string[0] != b_string[0]) {
+        return false;  // we know they don't match
     }
-    return (SDL_strcmp((const char *)a, (const char *)b) == 0);  // Check against actual string contents.
+    return (SDL_strcmp(a_string, b_string) == 0);  // Check against actual string contents.
 }
 
 // We assume we can fit the ID in the key directly