Micro-optimization: Avoid repeated calls to XQLength

This commit is contained in:
Kovid Goyal 2019-07-08 11:01:17 +05:30
parent 8f8138d9bd
commit d259b12ae7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

17
glfw/x11_window.c vendored
View File

@ -2473,14 +2473,12 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
} }
static inline unsigned static inline unsigned
dispatch_x11_queued_events(void) { dispatch_x11_queued_events(int num_events) {
unsigned dispatched = 0; unsigned dispatched = num_events > 0 ? num_events : 0;
while (XQLength(_glfw.x11.display) > 0) while (num_events-- > 0) {
{
XEvent event; XEvent event;
XNextEvent(_glfw.x11.display, &event); XNextEvent(_glfw.x11.display, &event);
processEvent(&event); processEvent(&event);
dispatched += 1;
} }
return dispatched; return dispatched;
} }
@ -2493,8 +2491,7 @@ _glfwDispatchX11Events(void) {
#if defined(__linux__) #if defined(__linux__)
_glfwDetectJoystickConnectionLinux(); _glfwDetectJoystickConnectionLinux();
#endif #endif
XPending(_glfw.x11.display); dispatched += dispatch_x11_queued_events(XEventsQueued(_glfw.x11.display, QueuedAfterFlush));
dispatched += dispatch_x11_queued_events();
window = _glfw.x11.disabledCursorWindow; window = _glfw.x11.disabledCursorWindow;
if (window) if (window)
@ -2512,8 +2509,10 @@ _glfwDispatchX11Events(void) {
} }
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
// XFlush can cause events to be queued // XFlush can cause events to be queued, we dont use QueuedAfterFlush here
dispatched += dispatch_x11_queued_events(); // as something might have inserted events into the queue, but we want to guarantee
// a flush.
dispatched += dispatch_x11_queued_events(XEventsQueued(_glfw.x11.display, QueuedAlready));
return dispatched; return dispatched;
} }