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.
authorSam Lantinga
Fri, 14 Dec 2012 09:22:13 -0800
changeset 6753332c36fd0fd7
parent 6752 8de11011eb1f
child 6754 c8cbb53af33e
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
src/joystick/SDL_joystick.c
     1.1 --- a/src/events/SDL_events.c	Thu Dec 13 22:26:30 2012 -0500
     1.2 +++ b/src/events/SDL_events.c	Fri Dec 14 09:22:13 2012 -0800
     1.3 @@ -70,9 +70,9 @@
     1.4  SDL_ShouldPollJoystick()
     1.5  {
     1.6  #if !SDL_JOYSTICK_DISABLED
     1.7 -    if (SDL_PrivateJoystickNeedsPolling() &&
     1.8 -        (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
     1.9 -         SDL_JoystickEventState(SDL_QUERY))) {
    1.10 +    if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
    1.11 +         SDL_JoystickEventState(SDL_QUERY)) &&
    1.12 +        SDL_PrivateJoystickNeedsPolling()) {
    1.13          return SDL_TRUE;
    1.14      }
    1.15  #endif
     2.1 --- a/src/joystick/SDL_joystick.c	Thu Dec 13 22:26:30 2012 -0500
     2.2 +++ b/src/joystick/SDL_joystick.c	Fri Dec 14 09:22:13 2012 -0800
     2.3 @@ -637,7 +637,7 @@
     2.4  SDL_JoystickEventState(int state)
     2.5  {
     2.6  #if SDL_EVENTS_DISABLED
     2.7 -    return SDL_IGNORE;
     2.8 +    return SDL_DISABLE;
     2.9  #else
    2.10      const Uint32 event_list[] = {
    2.11          SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
    2.12 @@ -647,7 +647,7 @@
    2.13  
    2.14      switch (state) {
    2.15      case SDL_QUERY:
    2.16 -        state = SDL_IGNORE;
    2.17 +        state = SDL_DISABLE;
    2.18          for (i = 0; i < SDL_arraysize(event_list); ++i) {
    2.19              state = SDL_EventState(event_list[i], SDL_QUERY);
    2.20              if (state == SDL_ENABLE) {
    2.21 @@ -669,15 +669,10 @@
    2.22  SDL_bool 
    2.23  SDL_PrivateJoystickNeedsPolling()
    2.24  {
    2.25 -	if ( SDL_SYS_JoystickNeedsPolling() )
    2.26 -	{
    2.27 -		// sys layer needs us to think
    2.28 +	if (SDL_joysticks != NULL) {
    2.29  		return SDL_TRUE;
    2.30 -	}
    2.31 -	else
    2.32 -	{
    2.33 -		// otherwise only do it if a joystick is opened
    2.34 -		return SDL_joysticks != NULL; 
    2.35 +	} else {
    2.36 +		return SDL_SYS_JoystickNeedsPolling();
    2.37  	}
    2.38  }
    2.39