diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-22 14:12:18 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-22 14:12:18 +0300 |
commit | 2c1d95177059c0486fca98ad1d43cdc0df7c5552 (patch) | |
tree | 4fe6ad3c9e5f7e228636e6a67ea76c15260d3bbc /src/app.c | |
parent | b53e1f203b57ab6deb088b50135ee49889356f84 (diff) |
Cleanup: Tidying up per-frame memory allocs
No need to use Garbage here to collect per-frame strings and arrays.
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 41 |
1 files changed, 24 insertions, 17 deletions
@@ -1155,13 +1155,13 @@ static iBool nextEvent_App_(iApp *d, enum iAppEventMode eventMode, SDL_Event *ev | |||
1155 | return SDL_PollEvent(event); | 1155 | return SDL_PollEvent(event); |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | static const iPtrArray *listWindows_App_(const iApp *d) { | 1158 | static iPtrArray *listWindows_App_(const iApp *d, iPtrArray *windows) { |
1159 | iPtrArray *list = collectNew_PtrArray(); | 1159 | clear_PtrArray(windows); |
1160 | iReverseConstForEach(PtrArray, i, &d->popupWindows) { | 1160 | iReverseConstForEach(PtrArray, i, &d->popupWindows) { |
1161 | pushBack_PtrArray(list, i.ptr); | 1161 | pushBack_PtrArray(windows, i.ptr); |
1162 | } | 1162 | } |
1163 | pushBack_PtrArray(list, d->window); | 1163 | pushBack_PtrArray(windows, d->window); |
1164 | return list; | 1164 | return windows; |
1165 | } | 1165 | } |
1166 | 1166 | ||
1167 | void processEvents_App(enum iAppEventMode eventMode) { | 1167 | void processEvents_App(enum iAppEventMode eventMode) { |
@@ -1169,6 +1169,8 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1169 | iRoot *oldCurrentRoot = current_Root(); /* restored afterwards */ | 1169 | iRoot *oldCurrentRoot = current_Root(); /* restored afterwards */ |
1170 | SDL_Event ev; | 1170 | SDL_Event ev; |
1171 | iBool gotEvents = iFalse; | 1171 | iBool gotEvents = iFalse; |
1172 | iPtrArray windows; | ||
1173 | init_PtrArray(&windows); | ||
1172 | while (nextEvent_App_(d, eventMode, &ev)) { | 1174 | while (nextEvent_App_(d, eventMode, &ev)) { |
1173 | #if defined (iPlatformAppleMobile) | 1175 | #if defined (iPlatformAppleMobile) |
1174 | if (processEvent_iOS(&ev)) { | 1176 | if (processEvent_iOS(&ev)) { |
@@ -1331,7 +1333,8 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1331 | #endif | 1333 | #endif |
1332 | /* Per-window processing. */ | 1334 | /* Per-window processing. */ |
1333 | iBool wasUsed = iFalse; | 1335 | iBool wasUsed = iFalse; |
1334 | iConstForEach(PtrArray, iter, listWindows_App_(d)) { | 1336 | listWindows_App_(d, &windows); |
1337 | iConstForEach(PtrArray, iter, &windows) { | ||
1335 | iWindow *window = iter.ptr; | 1338 | iWindow *window = iter.ptr; |
1336 | setCurrent_Window(window); | 1339 | setCurrent_Window(window); |
1337 | window->lastHover = window->hover; | 1340 | window->lastHover = window->hover; |
@@ -1364,7 +1367,8 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1364 | handleCommand_Win32(command_UserEvent(&ev)); | 1367 | handleCommand_Win32(command_UserEvent(&ev)); |
1365 | #endif | 1368 | #endif |
1366 | if (isMetricsChange_UserEvent(&ev)) { | 1369 | if (isMetricsChange_UserEvent(&ev)) { |
1367 | iConstForEach(PtrArray, iter, listWindows_App_(d)) { | 1370 | listWindows_App_(d, &windows); |
1371 | iConstForEach(PtrArray, iter, &windows) { | ||
1368 | iWindow *window = iter.ptr; | 1372 | iWindow *window = iter.ptr; |
1369 | iForIndices(i, window->roots) { | 1373 | iForIndices(i, window->roots) { |
1370 | iRoot *root = window->roots[i]; | 1374 | iRoot *root = window->roots[i]; |
@@ -1383,7 +1387,8 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1383 | free(ev.user.data1); | 1387 | free(ev.user.data1); |
1384 | } | 1388 | } |
1385 | /* Refresh after hover changes. */ { | 1389 | /* Refresh after hover changes. */ { |
1386 | iConstForEach(PtrArray, iter, listWindows_App_(d)) { | 1390 | listWindows_App_(d, &windows); |
1391 | iConstForEach(PtrArray, iter, &windows) { | ||
1387 | iWindow *window = iter.ptr; | 1392 | iWindow *window = iter.ptr; |
1388 | if (window->lastHover != window->hover) { | 1393 | if (window->lastHover != window->hover) { |
1389 | refresh_Widget(window->lastHover); | 1394 | refresh_Widget(window->lastHover); |
@@ -1395,6 +1400,7 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1395 | } | 1400 | } |
1396 | } | 1401 | } |
1397 | } | 1402 | } |
1403 | deinit_PtrArray(&windows); | ||
1398 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) | 1404 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1399 | if (d->isIdling && !gotEvents) { | 1405 | if (d->isIdling && !gotEvents) { |
1400 | /* This is where we spend most of our time when idle. 60 Hz still quite a lot but we | 1406 | /* This is where we spend most of our time when idle. 60 Hz still quite a lot but we |
@@ -1482,9 +1488,11 @@ void refresh_App(void) { | |||
1482 | return; | 1488 | return; |
1483 | } | 1489 | } |
1484 | #endif | 1490 | #endif |
1485 | const iPtrArray *windows = listWindows_App_(d); | 1491 | iPtrArray windows; |
1492 | init_PtrArray(&windows); | ||
1493 | listWindows_App_(d, &windows); | ||
1486 | /* Destroy pending widgets. */ { | 1494 | /* Destroy pending widgets. */ { |
1487 | iConstForEach(PtrArray, j, windows) { | 1495 | iConstForEach(PtrArray, j, &windows) { |
1488 | iWindow *win = j.ptr; | 1496 | iWindow *win = j.ptr; |
1489 | setCurrent_Window(win); | 1497 | setCurrent_Window(win); |
1490 | iForIndices(i, win->roots) { | 1498 | iForIndices(i, win->roots) { |
@@ -1495,12 +1503,10 @@ void refresh_App(void) { | |||
1495 | } | 1503 | } |
1496 | } | 1504 | } |
1497 | } | 1505 | } |
1498 | /* TODO: Pending refresh is window-specific. */ | 1506 | /* TODO: `pendingRefresh` should be window-specific. */ |
1499 | if (!exchange_Atomic(&d->pendingRefresh, iFalse)) { | 1507 | if (exchange_Atomic(&d->pendingRefresh, iFalse)) { |
1500 | return; | 1508 | /* Draw each window. */ |
1501 | } | 1509 | iConstForEach(PtrArray, j, &windows) { |
1502 | /* Draw each window. */ { | ||
1503 | iConstForEach(PtrArray, j, windows) { | ||
1504 | iWindow *win = j.ptr; | 1510 | iWindow *win = j.ptr; |
1505 | setCurrent_Window(win); | 1511 | setCurrent_Window(win); |
1506 | switch (win->type) { | 1512 | switch (win->type) { |
@@ -1520,6 +1526,7 @@ void refresh_App(void) { | |||
1520 | if (d->warmupFrames > 0) { | 1526 | if (d->warmupFrames > 0) { |
1521 | d->warmupFrames--; | 1527 | d->warmupFrames--; |
1522 | } | 1528 | } |
1529 | deinit_PtrArray(&windows); | ||
1523 | } | 1530 | } |
1524 | 1531 | ||
1525 | iBool isRefreshPending_App(void) { | 1532 | iBool isRefreshPending_App(void) { |
@@ -2096,7 +2103,7 @@ const iString *searchQueryUrl_App(const iString *queryStringUnescaped) { | |||
2096 | 2103 | ||
2097 | void resetFonts_App(void) { | 2104 | void resetFonts_App(void) { |
2098 | iApp *d = &app_; | 2105 | iApp *d = &app_; |
2099 | iConstForEach(PtrArray, win, listWindows_App_(d)) { | 2106 | iConstForEach(PtrArray, win, listWindows_App_(d, collectNew_PtrArray())) { |
2100 | resetFonts_Text(text_Window(win.ptr)); | 2107 | resetFonts_Text(text_Window(win.ptr)); |
2101 | } | 2108 | } |
2102 | } | 2109 | } |