Micro-optimization: Avoid repeated calls to XQLength
This commit is contained in:
parent
8f8138d9bd
commit
d259b12ae7
17
glfw/x11_window.c
vendored
17
glfw/x11_window.c
vendored
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user