From 2aac14fa9b699e8c647abcc82ac113b8760ee41d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 14 Dec 2012 09:22:13 -0800 Subject: [PATCH] Only check SDL_SYS_JoystickNeedsPolling() if we know we don't need to poll for other reasons. This avoids a select() syscall on Linux if it isn't necessary. --- src/events/SDL_events.c | 6 +++--- src/joystick/SDL_joystick.c | 15 +++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index c6aa97415..f0a6df686 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -70,9 +70,9 @@ static __inline__ SDL_bool SDL_ShouldPollJoystick() { #if !SDL_JOYSTICK_DISABLED - if (SDL_PrivateJoystickNeedsPolling() && - (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || - SDL_JoystickEventState(SDL_QUERY))) { + if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || + SDL_JoystickEventState(SDL_QUERY)) && + SDL_PrivateJoystickNeedsPolling()) { return SDL_TRUE; } #endif diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index fe45a023d..b9aa0f467 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -637,7 +637,7 @@ int SDL_JoystickEventState(int state) { #if SDL_EVENTS_DISABLED - return SDL_IGNORE; + return SDL_DISABLE; #else const Uint32 event_list[] = { SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, @@ -647,7 +647,7 @@ SDL_JoystickEventState(int state) switch (state) { case SDL_QUERY: - state = SDL_IGNORE; + state = SDL_DISABLE; for (i = 0; i < SDL_arraysize(event_list); ++i) { state = SDL_EventState(event_list[i], SDL_QUERY); if (state == SDL_ENABLE) { @@ -669,15 +669,10 @@ SDL_JoystickEventState(int state) SDL_bool SDL_PrivateJoystickNeedsPolling() { - if ( SDL_SYS_JoystickNeedsPolling() ) - { - // sys layer needs us to think + if (SDL_joysticks != NULL) { return SDL_TRUE; - } - else - { - // otherwise only do it if a joystick is opened - return SDL_joysticks != NULL; + } else { + return SDL_SYS_JoystickNeedsPolling(); } }