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.

This commit is contained in:
Sam Lantinga 2012-12-14 09:22:13 -08:00
parent 6b4cb17219
commit 80493dfae0
2 changed files with 8 additions and 13 deletions

View file

@ -70,9 +70,9 @@ static __inline__ SDL_bool
SDL_ShouldPollJoystick() SDL_ShouldPollJoystick()
{ {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateJoystickNeedsPolling() && if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
(!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY)) &&
SDL_JoystickEventState(SDL_QUERY))) { SDL_PrivateJoystickNeedsPolling()) {
return SDL_TRUE; return SDL_TRUE;
} }
#endif #endif

View file

@ -637,7 +637,7 @@ int
SDL_JoystickEventState(int state) SDL_JoystickEventState(int state)
{ {
#if SDL_EVENTS_DISABLED #if SDL_EVENTS_DISABLED
return SDL_IGNORE; return SDL_DISABLE;
#else #else
const Uint32 event_list[] = { const Uint32 event_list[] = {
SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
@ -647,7 +647,7 @@ SDL_JoystickEventState(int state)
switch (state) { switch (state) {
case SDL_QUERY: case SDL_QUERY:
state = SDL_IGNORE; state = SDL_DISABLE;
for (i = 0; i < SDL_arraysize(event_list); ++i) { for (i = 0; i < SDL_arraysize(event_list); ++i) {
state = SDL_EventState(event_list[i], SDL_QUERY); state = SDL_EventState(event_list[i], SDL_QUERY);
if (state == SDL_ENABLE) { if (state == SDL_ENABLE) {
@ -669,15 +669,10 @@ SDL_JoystickEventState(int state)
SDL_bool SDL_bool
SDL_PrivateJoystickNeedsPolling() SDL_PrivateJoystickNeedsPolling()
{ {
if ( SDL_SYS_JoystickNeedsPolling() ) if (SDL_joysticks != NULL) {
{
// sys layer needs us to think
return SDL_TRUE; return SDL_TRUE;
} } else {
else return SDL_SYS_JoystickNeedsPolling();
{
// otherwise only do it if a joystick is opened
return SDL_joysticks != NULL;
} }
} }