SDL: Grab events in large chunks in SDL_IterateMainCallbacks()

From e0379c3b37cb71efb97719899d266d7ec9c1b435 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 3 Nov 2023 21:47:44 -0700
Subject: [PATCH] Grab events in large chunks in SDL_IterateMainCallbacks()

This is more efficient, especially since we're just going to discard them.
---
 src/main/SDL_main_callbacks.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/main/SDL_main_callbacks.c b/src/main/SDL_main_callbacks.c
index 5d880066df24..a20f9f6ac862 100644
--- a/src/main/SDL_main_callbacks.c
+++ b/src/main/SDL_main_callbacks.c
@@ -81,15 +81,22 @@ int SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func appinit, SDL_
 
 int SDL_IterateMainCallbacks(void)
 {
-    SDL_Event event;
+    // Just pump events and empty the queue, EventWatcher sends the events to the app.
     SDL_PumpEvents();
-    while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST) == 1) {
-        // just empty the queue, EventWatcher sends the events to the app.
-        switch (event.type) {
+
+    for (;;) {
+        SDL_Event events[32];
+        int count = SDL_PeepEvents(events, SDL_arraysize(events), SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST);
+        if (count <= 0) {
+            break;
+        }
+        for (int i = 0; i < count; ++i) {
+            switch (events[i].type) {
             case SDL_EVENT_DROP_FILE:
             case SDL_EVENT_DROP_TEXT:
-                SDL_free(event.drop.file);
+                SDL_free(events[i].drop.file);
                 break;
+            }
         }
     }