mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Make timer dispatch more efficient
This commit is contained in:
4
glfw/backend_utils.c
vendored
4
glfw/backend_utils.c
vendored
@@ -179,15 +179,13 @@ dispatchTimers(EventLoopData *eld) {
|
|||||||
static struct { timer_callback_func func; id_type id; void* data; } dispatches[sizeof(eld->timers)/sizeof(eld->timers[0])];
|
static struct { timer_callback_func func; id_type id; void* data; } dispatches[sizeof(eld->timers)/sizeof(eld->timers[0])];
|
||||||
unsigned num_dispatches = 0;
|
unsigned num_dispatches = 0;
|
||||||
double now = monotonic();
|
double now = monotonic();
|
||||||
for (nfds_t i = 0; i < eld->timers_count && eld->timers[i].trigger_at < DBL_MAX; i++) {
|
for (nfds_t i = 0; i < eld->timers_count && eld->timers[i].trigger_at <= now; i++) {
|
||||||
if (eld->timers[i].trigger_at <= now) {
|
|
||||||
eld->timers[i].trigger_at = now + eld->timers[i].interval;
|
eld->timers[i].trigger_at = now + eld->timers[i].interval;
|
||||||
dispatches[num_dispatches].func = eld->timers[i].callback;
|
dispatches[num_dispatches].func = eld->timers[i].callback;
|
||||||
dispatches[num_dispatches].id = eld->timers[i].id;
|
dispatches[num_dispatches].id = eld->timers[i].id;
|
||||||
dispatches[num_dispatches].data = eld->timers[i].callback_data;
|
dispatches[num_dispatches].data = eld->timers[i].callback_data;
|
||||||
num_dispatches++;
|
num_dispatches++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// we dispatch separately so that the callbacks can modify timers
|
// we dispatch separately so that the callbacks can modify timers
|
||||||
for (unsigned i = 0; i < num_dispatches; i++) {
|
for (unsigned i = 0; i < num_dispatches; i++) {
|
||||||
dispatches[i].func(dispatches[i].id, dispatches[i].data);
|
dispatches[i].func(dispatches[i].id, dispatches[i].data);
|
||||||
|
|||||||
Reference in New Issue
Block a user