]> git.earman.xyz Git - sensor-watch.git/commitdiff
use __builtin_ctz when processing pending events
authorAlessandro Genova <ales.genova@gmail.com>
Sat, 13 Sep 2025 01:41:59 +0000 (21:41 -0400)
committerAlessandro Genova <ales.genova@gmail.com>
Sat, 3 Jan 2026 01:07:56 +0000 (20:07 -0500)
movement.c

index 14944bea8efe6fdc4769c7373f94f9e2fadb8f6e..c1a5d08790600ad429b96abd779db31dae21b1d4 100644 (file)
@@ -1223,12 +1223,11 @@ bool app_loop(void) {
     // Consume all the pending events
     movement_event_type_t event_type = 0;
     while (pending_events) {
-        if (pending_events & 1) {
-            event.event_type = event_type;
-            can_sleep = wf->loop(event, watch_face_contexts[movement_state.current_face_idx]) && can_sleep;
-        }
-        pending_events = pending_events >> 1;
-        event_type++;
+        uint8_t next_event = __builtin_ctz(pending_events);
+        event.event_type = event_type + next_event;
+        can_sleep = wf->loop(event, watch_face_contexts[movement_state.current_face_idx]) && can_sleep;
+        pending_events = pending_events >> (next_event + 1);
+        event_type = event_type + next_event + 1;
     }
 
     // handle top-of-minute tasks, if the alarm handler told us we need to