Commit 27a48b142bb53def7e1e6fafcdb5433d3b6a5865

Sam Lantinga 2021-09-07T15:50:21

Check the pathname first, as that's a faster check for XInput devices

diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index 4854df3..f334c00 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -242,6 +242,12 @@ SDL_IsXInputDevice(Uint16 vendor_id, Uint16 product_id, const char* hidPath)
         return SDL_FALSE;
     }
 
+    /* If device path contains "IG_" then its an XInput device */
+    /* See: https://docs.microsoft.com/windows/win32/xinput/xinput-and-directinput */
+    if (SDL_strstr(hidPath, "IG_") != NULL) {
+        return SDL_TRUE;
+    }
+
     type = SDL_GetJoystickGameControllerType("", vendor_id, product_id, -1, 0, 0, 0);
     if (type == SDL_CONTROLLER_TYPE_XBOX360 ||
         type == SDL_CONTROLLER_TYPE_XBOXONE ||
@@ -249,12 +255,6 @@ SDL_IsXInputDevice(Uint16 vendor_id, Uint16 product_id, const char* hidPath)
         return SDL_TRUE;
     }
 
-    /* If device path contains "IG_" then its an XInput device */
-    /* See: https://docs.microsoft.com/windows/win32/xinput/xinput-and-directinput */
-    if (SDL_strstr(hidPath, "IG_") != NULL) {
-        return SDL_TRUE;
-    }
-
     return SDL_FALSE;
 }