SDL: Removed acquire/release of keymaps, which isn't needed internally.

From ac7df9d01f118e1d240331c7b4abfaae09250eba Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Aug 2024 18:19:39 -0700
Subject: [PATCH] Removed acquire/release of keymaps, which isn't needed
 internally.

---
 src/events/SDL_keyboard.c             |  6 ++----
 src/events/SDL_keymap.c               | 21 ++-------------------
 src/events/SDL_keymap_c.h             |  3 +--
 src/video/wayland/SDL_waylandevents.c |  2 +-
 4 files changed, 6 insertions(+), 26 deletions(-)

diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index e4788a71d0c3b..fc23ebe317ba5 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -229,8 +229,6 @@ SDL_Keymap *SDL_GetCurrentKeymap(void)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
 
-    SDL_AcquireKeymap(keyboard->keymap);
-
     return keyboard->keymap;
 }
 
@@ -239,7 +237,7 @@ void SDL_SetKeymap(SDL_Keymap *keymap, SDL_bool send_event)
     SDL_Keyboard *keyboard = &SDL_keyboard;
 
     if (keyboard->keymap) {
-        SDL_ReleaseKeymap(keyboard->keymap);
+        SDL_DestroyKeymap(keyboard->keymap);
     }
 
     keyboard->keymap = keymap;
@@ -851,7 +849,7 @@ void SDL_QuitKeyboard(void)
     SDL_keyboards = NULL;
 
     if (SDL_keyboard.keymap) {
-        SDL_ReleaseKeymap(SDL_keyboard.keymap);
+        SDL_DestroyKeymap(SDL_keyboard.keymap);
         SDL_keyboard.keymap = NULL;
     }
 
diff --git a/src/events/SDL_keymap.c b/src/events/SDL_keymap.c
index 452ee24a98883..054fb0950786e 100644
--- a/src/events/SDL_keymap.c
+++ b/src/events/SDL_keymap.c
@@ -26,7 +26,6 @@
 
 struct SDL_Keymap
 {
-    int refcount;
     SDL_HashTable *scancode_to_keycode;
     SDL_HashTable *keycode_to_scancode;
 };
@@ -41,23 +40,15 @@ SDL_Keymap *SDL_CreateKeymap(void)
         return NULL;
     }
 
-    keymap->refcount = 1;
     keymap->scancode_to_keycode = SDL_CreateHashTable(NULL, 64, SDL_HashID, SDL_KeyMatchID, NULL, SDL_FALSE);
     keymap->keycode_to_scancode = SDL_CreateHashTable(NULL, 64, SDL_HashID, SDL_KeyMatchID, NULL, SDL_FALSE);
     if (!keymap->scancode_to_keycode || !keymap->keycode_to_scancode) {
-        SDL_ReleaseKeymap(keymap);
+        SDL_DestroyKeymap(keymap);
         return NULL;
     }
     return keymap;
 }
 
-void SDL_AcquireKeymap(SDL_Keymap *keymap)
-{
-    if (keymap) {
-        ++keymap->refcount;
-    }
-}
-
 static SDL_Keymod NormalizeModifierStateForKeymap(SDL_Keymod modstate)
 {
     // The modifiers that affect the keymap are: SHIFT, CAPS, ALT, and MODE
@@ -128,17 +119,12 @@ SDL_Scancode SDL_GetKeymapScancode(SDL_Keymap *keymap, SDL_Keycode keycode, SDL_
     return scancode;
 }
 
-void SDL_ReleaseKeymap(SDL_Keymap *keymap)
+void SDL_DestroyKeymap(SDL_Keymap *keymap)
 {
     if (!keymap) {
         return;
     }
 
-    --keymap->refcount;
-    if (keymap->refcount != 0) {
-        return;
-    }
-
     SDL_DestroyHashTable(keymap->scancode_to_keycode);
     SDL_DestroyHashTable(keymap->keycode_to_scancode);
     SDL_free(keymap);
@@ -1030,7 +1016,6 @@ const char *SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase)
                 if (scancode != SDL_SCANCODE_UNKNOWN) {
                     if (key >= 0x0E00 && key <= 0x0E7F) {
                         // Thai keyboards are QWERTY plus Thai characters, so let's use the ASCII key names
-                        SDL_ReleaseKeymap(keymap);
                         return SDL_GetScancodeName(scancode);
                     }
 
@@ -1039,7 +1024,6 @@ const char *SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase)
                         key = capital;
                     }
                 }
-                SDL_ReleaseKeymap(keymap);
             }
         }
 
@@ -1108,7 +1092,6 @@ SDL_Keycode SDL_GetKeyFromName(const char *name, SDL_bool uppercase)
                 if (scancode != SDL_SCANCODE_UNKNOWN && (modstate & SDL_KMOD_SHIFT)) {
                     key = SDL_GetKeymapKeycode(keymap, scancode, SDL_KMOD_NONE);
                 }
-                SDL_ReleaseKeymap(keymap);
             }
         }
         return key;
diff --git a/src/events/SDL_keymap_c.h b/src/events/SDL_keymap_c.h
index d6b4f1803b2c9..72da37a373a08 100644
--- a/src/events/SDL_keymap_c.h
+++ b/src/events/SDL_keymap_c.h
@@ -27,10 +27,9 @@ typedef struct SDL_Keymap SDL_Keymap;
 
 SDL_Keymap *SDL_GetCurrentKeymap(void);
 SDL_Keymap *SDL_CreateKeymap(void);
-void SDL_AcquireKeymap(SDL_Keymap *keymap);
 void SDL_SetKeymapEntry(SDL_Keymap *keymap, SDL_Scancode scancode, SDL_Keymod modstate, SDL_Keycode keycode);
 SDL_Keycode SDL_GetKeymapKeycode(SDL_Keymap *keymap, SDL_Scancode scancode, SDL_Keymod modstate);
 SDL_Scancode SDL_GetKeymapScancode(SDL_Keymap *keymap, SDL_Keycode keycode, SDL_Keymod *modstate);
-void SDL_ReleaseKeymap(SDL_Keymap *keymap);
+void SDL_DestroyKeymap(SDL_Keymap *keymap);
 
 #endif /* SDL_keymap_c_h_ */
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 3f9aa8663dea6..70a79586eb721 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -1185,7 +1185,7 @@ static void Wayland_UpdateKeymap(struct SDL_WaylandInput *input)
         keymap.state = WAYLAND_xkb_state_new(input->xkb.keymap);
         if (!keymap.state) {
             SDL_SetError("failed to create XKB state");
-            SDL_ReleaseKeymap(keymap.keymap);
+            SDL_DestroyKeymap(keymap.keymap);
             return;
         }