mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2025-04-06 03:58:02 +08:00
Add items in sorted order instead of adding then sorting.
This commit is contained in:
parent
48c997d793
commit
ea4ea253a7
@ -141,6 +141,24 @@ bool linked_list_add_at(linked_list* list, unsigned int index, void* value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void linked_list_add_sorted(linked_list* list, void* value, void* userData, int (*compare)(void* userData, const void* p1, const void* p2)) {
|
||||||
|
if(compare != NULL) {
|
||||||
|
unsigned int i = 0;
|
||||||
|
linked_list_node* node = list->first;
|
||||||
|
while(node != NULL) {
|
||||||
|
if(compare(userData, value, node->value) < 0) {
|
||||||
|
linked_list_add_at(list, i, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
linked_list_add(list, value);
|
||||||
|
}
|
||||||
|
|
||||||
static void linked_list_remove_node(linked_list* list, linked_list_node* node) {
|
static void linked_list_remove_node(linked_list* list, linked_list_node* node) {
|
||||||
if(node->prev != NULL) {
|
if(node->prev != NULL) {
|
||||||
node->prev->next = node->next;
|
node->prev->next = node->next;
|
||||||
|
@ -30,6 +30,7 @@ int linked_list_index_of(linked_list* list, void* value);
|
|||||||
void* linked_list_get(linked_list* list, unsigned int index);
|
void* linked_list_get(linked_list* list, unsigned int index);
|
||||||
bool linked_list_add(linked_list* list, void* value);
|
bool linked_list_add(linked_list* list, void* value);
|
||||||
bool linked_list_add_at(linked_list* list, unsigned int index, void* value);
|
bool linked_list_add_at(linked_list* list, unsigned int index, void* value);
|
||||||
|
void linked_list_add_sorted(linked_list* list, void* value, void* userData, int (*compare)(void* userData, const void* p1, const void* p2));
|
||||||
bool linked_list_remove(linked_list* list, void* value);
|
bool linked_list_remove(linked_list* list, void* value);
|
||||||
bool linked_list_remove_at(linked_list* list, unsigned int index);
|
bool linked_list_remove_at(linked_list* list, unsigned int index);
|
||||||
void linked_list_sort(linked_list* list, void* userData, int (*compare)(void* userData, const void* p1, const void* p2));
|
void linked_list_sort(linked_list* list, void* userData, int (*compare)(void* userData, const void* p1, const void* p2));
|
||||||
|
@ -81,11 +81,7 @@ static Result task_populate_ext_save_data_from(populate_ext_save_data_data* data
|
|||||||
|
|
||||||
item->data = extSaveDataInfo;
|
item->data = extSaveDataInfo;
|
||||||
|
|
||||||
linked_list_add(data->items, item);
|
linked_list_add_sorted(data->items, item, data->userData, data->compare);
|
||||||
|
|
||||||
if(data->compare != NULL) {
|
|
||||||
linked_list_sort(data->items, data->userData, data->compare);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
free(item);
|
free(item);
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ static Result task_populate_titles_add_ctr(populate_titles_data* data, FS_MediaT
|
|||||||
|
|
||||||
item->data = titleInfo;
|
item->data = titleInfo;
|
||||||
|
|
||||||
linked_list_add(data->items, item);
|
linked_list_add_sorted(data->items, item, data->userData, data->compare);
|
||||||
} else {
|
} else {
|
||||||
free(item);
|
free(item);
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ static Result task_populate_titles_add_twl(populate_titles_data* data, FS_MediaT
|
|||||||
item->color = COLOR_DS_TITLE;
|
item->color = COLOR_DS_TITLE;
|
||||||
item->data = titleInfo;
|
item->data = titleInfo;
|
||||||
|
|
||||||
linked_list_add(data->items, item);
|
linked_list_add_sorted(data->items, item, data->userData, data->compare);
|
||||||
} else {
|
} else {
|
||||||
free(item);
|
free(item);
|
||||||
|
|
||||||
@ -256,9 +256,7 @@ static Result task_populate_titles_from(populate_titles_data* data, FS_MediaType
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(R_SUCCEEDED(res = dsiWare ? task_populate_titles_add_twl(data, mediaType, titleIds[i]) : task_populate_titles_add_ctr(data, mediaType, titleIds[i])) && data->compare != NULL) {
|
res = dsiWare ? task_populate_titles_add_twl(data, mediaType, titleIds[i]) : task_populate_titles_add_ctr(data, mediaType, titleIds[i]);
|
||||||
linked_list_sort(data->items, data->userData, data->compare);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user