mirror of
https://github.com/joel16/VITA-Homebrew-Sorter.git
synced 2024-12-04 01:11:25 +00:00
applist: Optimize sort query by preprocessing folder indices into a map
This commit is contained in:
parent
b12dc03dea
commit
3d9a9677e7
@ -345,27 +345,32 @@ namespace AppList {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sort(AppEntries &entries) {
|
void Sort(AppEntries &entries) {
|
||||||
|
const int MAX_POS = 9;
|
||||||
int pos = 0, pageCounter = 0;
|
int pos = 0, pageCounter = 0;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < entries.icons.size(); i ++) {
|
std::unordered_map<int, int> folderIndexMap;
|
||||||
|
for (AppInfoFolder folder : entries.folders) {
|
||||||
|
folderIndexMap[folder.pageId] = folder.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < entries.icons.size(); i++) {
|
||||||
// Reset position
|
// Reset position
|
||||||
if (pos > 9) {
|
if (pos > MAX_POS) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
pageCounter++;
|
pageCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// App/Game belongs to a folder
|
// App/Game belongs to a folder
|
||||||
if ((entries.icons[i].pageNo < 0) && (cfg.sort_folders == SortBoth || cfg.sort_folders == SortFoldersOnly)) {
|
if ((entries.icons[i].pageNo < 0) && (cfg.sort_folders != SortAppsOnly)) {
|
||||||
for (unsigned int j = 0; j < entries.folders.size(); j++) {
|
int it = folderIndexMap.find(entries.icons[i].pageId);
|
||||||
if (entries.icons[i].pageId == entries.folders[j].pageId) {
|
if (it != folderIndexMap.end()) {
|
||||||
entries.icons[i].pos = entries.folders[j].index;
|
entries.icons[i].pos = it->second;
|
||||||
entries.folders[j].index++;
|
folderIndexMap[entries.icons[i].pageId]++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((entries.icons[i].pageNo >= 0) && (cfg.sort_folders == SortBoth || cfg.sort_folders == SortAppsOnly)) {
|
else if ((entries.icons[i].pageNo >= 0) && (cfg.sort_folders != SortFoldersOnly)) {
|
||||||
entries.icons[i].pos = pos;
|
entries.icons[i].pos = pos;
|
||||||
entries.icons[i].pageId = entries.pages[pageCounter].pageId;
|
entries.icons[i].pageId = entries.pages[pageCounter].pageId;
|
||||||
pos++;
|
pos++;
|
||||||
|
Loading…
Reference in New Issue
Block a user