mGUI: Skip second scan loop when possible
Vicki Pfau vi@endrift.com
Thu, 26 Nov 2020 22:33:05 -0800
2 files changed,
47 insertions(+),
45 deletions(-)
M
CHANGES
→
CHANGES
@@ -92,6 +92,7 @@ - GBA Video: Convert OpenGL VRAM texture to integer
- Debugger: Keep track of global cycle count - FFmpeg: Add looping option for GIF/APNG - mGUI: Show battery percentage + - mGUI: Skip second scan loop when possible - Qt: Renderer can be changed while a game is running - Qt: Add hex index to palette view - Qt: Add transformation matrix info to sprite view
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -89,6 +89,8 @@ size_t len = strlen(name) + 2;
char* n2 = malloc(len); snprintf(n2, len, "%s/", name); name = n2; + } else if (filterName && !filterName(name)) { + continue; } else { name = strdup(name); }@@ -96,59 +98,58 @@ *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = name, .data = (void*) de->type(de) };
++items; } qsort(GUIMenuItemListGetPointer(currentFiles, 1), GUIMenuItemListSize(currentFiles) - 1, sizeof(struct GUIMenuItem), _strpcmp); - i = 0; - size_t item = 0; - while (item < GUIMenuItemListSize(currentFiles)) { - ++i; - if (!(i % SCANNING_THRESHOLD_2)) { - uint32_t input = 0; - GUIPollInput(params, &input, 0); - if (input & (1 << GUI_INPUT_CANCEL)) { - dir->close(dir); - return false; - } + if (preselect || filterContents) { + i = 0; + size_t item = 0; + while (item < GUIMenuItemListSize(currentFiles)) { + ++i; + // If we're not filtering the contents, this loop is fast, so there's no need to show updates + if (filterContents && !(i % SCANNING_THRESHOLD_2)) { + uint32_t input = 0; + GUIPollInput(params, &input, 0); + if (input & (1 << GUI_INPUT_CANCEL)) { + dir->close(dir); + return false; + } - params->drawStart(); - if (params->guiPrepare) { - params->guiPrepare(); + params->drawStart(); + if (params->guiPrepare) { + params->guiPrepare(); + } + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_ALIGN_LEFT, 0xFFFFFFFF, "(scanning item %"PRIz"u of %"PRIz"u)", i, items); + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_ALIGN_LEFT, 0xFFFFFFFF, "%s", currentPath); + if (params->guiFinish) { + params->guiFinish(); + } + params->drawEnd(); } - GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_ALIGN_LEFT, 0xFFFFFFFF, "(scanning item %"PRIz"u of %"PRIz"u)", i, items); - GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_ALIGN_LEFT, 0xFFFFFFFF, "%s", currentPath); - if (params->guiFinish) { - params->guiFinish(); + struct GUIMenuItem* testItem = GUIMenuItemListGetPointer(currentFiles, item); + if (testItem->data != (void*) VFS_FILE) { + ++item; + continue; } - params->drawEnd(); - } - struct GUIMenuItem* testItem = GUIMenuItemListGetPointer(currentFiles, item); - if (testItem->data != (void*) VFS_FILE) { - ++item; - continue; - } - bool failed = false; - if (filterName && !filterName(testItem->title)) { - failed = true; - } - - if (!failed && filterContents) { - struct VFile* vf = dir->openFile(dir, testItem->title, O_RDONLY); - if (!vf) { - failed = true; - } else { - if (!filterContents(vf)) { + bool failed = false; + if (filterContents) { + struct VFile* vf = dir->openFile(dir, testItem->title, O_RDONLY); + if (!vf) { failed = true; + } else { + if (!filterContents(vf)) { + failed = true; + } + vf->close(vf); } - vf->close(vf); } - } - if (failed) { - free((char*) testItem->title); - GUIMenuItemListShift(currentFiles, item, 1); - } else { - if (preselect && strncmp(testItem->title, preselect, PATH_MAX) == 0) { - params->fileIndex = item; + if (failed) { + free((char*) testItem->title); + GUIMenuItemListShift(currentFiles, item, 1); + } else { + if (preselect && strncmp(testItem->title, preselect, PATH_MAX) == 0) { + params->fileIndex = item; + } + ++item; } - ++item; } } dir->close(dir);