Skip to content

Commit

Permalink
Merge pull request #236 from walkero-gr/load-list-optimisations
Browse files Browse the repository at this point in the history
Optimisation in list loading
  • Loading branch information
walkero-gr authored Feb 18, 2024
2 parents e9b1509 + b76e366 commit ad0cb1f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## iGame VERSION_TAG - [RELEASE_DATE]
### Changed
- Some optimisation in list loading reducing the time needed more than 42%

## iGame 2.4.4 - [2023-09-11]
### Changed
- Speedup the slavesListAddTail(), almost 200% faster. This has an impact on the slaves list creation during the scan and the loading from the file.

### Fixed
Expand Down
9 changes: 5 additions & 4 deletions src/fsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,23 @@ BOOL get_filename(const char *title, const char *positive_text, const BOOL save_

void slavesListLoadFromCSV(char *filename)
{
int lineBufSize = sizeof(char) * 1024;
int lineBufSize = sizeof(char) * 512;

if (check_path_exists(filename))
{
const BPTR fpgames = Open((CONST_STRPTR) filename, MODE_OLDFILE);
FILE *fpgames = fopen(filename, "r");
if (fpgames)
{
char *lineBuf = AllocVec(lineBufSize, MEMF_CLEAR);
char *buf = AllocVec(sizeof(char) * MAX_PATH_SIZE, MEMF_CLEAR);
if((buf == NULL) || (lineBuf == NULL))
{
msg_box((const char*)GetMBString(MSG_NotEnoughMemory));
fclose(fpgames);
return;
}

while (FGets(fpgames, lineBuf, lineBufSize) != NULL)
while (fgets(lineBuf, lineBufSize, fpgames) != NULL)
{
slavesList *node = malloc(sizeof(slavesList));
if(node == NULL)
Expand Down Expand Up @@ -282,7 +283,7 @@ void slavesListLoadFromCSV(char *filename)

slavesListAddTail(node);
}
Close(fpgames);
fclose(fpgames);
FreeVec(lineBuf);
}
}
Expand Down
23 changes: 10 additions & 13 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static void populateGenresList(void)
int cnt = 0;
while (currPtr != NULL)
{
DoMethod(app->LV_GenresList, MUIM_List_InsertSingle, currPtr->title, MUIV_List_Insert_Sorted);
DoMethod(app->LV_GenresList, MUIM_List_InsertSingle, currPtr->title, MUIV_List_Insert_Bottom);

cnt++;
currPtr = currPtr->next;
Expand All @@ -323,6 +323,8 @@ static void populateGenresList(void)
app->CY_PropertiesGenreContent[i++] = NULL;
set(app->CY_PropertiesGenre, MUIA_Cycle_Entries, app->CY_PropertiesGenreContent);
set(app->CY_AddGameGenre, MUIA_Cycle_Entries, app->CY_PropertiesGenreContent);
set(app->LV_GenresList, MUIA_List_Active, MUIV_List_Active_Top);
DoMethod(app->LV_GenresList, MUIM_List_Sort);
set(app->LV_GenresList, MUIA_List_Quiet, FALSE);
}

Expand Down Expand Up @@ -360,7 +362,6 @@ void app_start(void)
load_repos(DEFAULT_REPOS_FILE);
apply_settings();


if (current_settings->start_with_favorites)
{
filters.showGroup = GROUP_FAVOURITES;
Expand All @@ -381,7 +382,7 @@ void app_start(void)

if (!current_settings->hide_side_panel)
{
populateGenresList();
populateGenresList(); // This calls the filter_change()
populateChipsetList();
}
if (current_settings->hide_side_panel)
Expand Down Expand Up @@ -682,19 +683,14 @@ static void showSlavesList(void)
{
if (currPtr->times_played < mostPlayedTimes)
{
// DoMethod(app->LV_GamesList,
// MUIM_List_InsertSingle, currPtr->title,
// MUIV_List_Insert_Bottom);
DoMethod(app->LV_GamesList,
MUIM_NList_InsertSingle, currPtr,
MUIV_NList_Insert_Bottom);
}
else
{
mostPlayedTimes = currPtr->times_played;
// DoMethod(app->LV_GamesList,
// MUIM_List_InsertSingle, currPtr->title,
// MUIV_List_Insert_Top);

DoMethod(app->LV_GamesList,
MUIM_NList_InsertSingle, currPtr,
MUIV_NList_Insert_Top);
Expand All @@ -713,14 +709,15 @@ static void showSlavesList(void)

DoMethod(app->LV_GamesList,
MUIM_NList_InsertSingle, currPtr,
MUIV_NList_Insert_Sorted);
MUIV_NList_Insert_Bottom);

cnt++;
nextItem:
}

currPtr = currPtr->next;
}
DoMethod(app->LV_GamesList, MUIM_NList_Sort);
set(app->LV_GamesList, MUIA_NList_Quiet, FALSE);

sprintf(buf, (const char *)GetMBString(MSG_TotalNumberOfGames), slavesListNodeCount(cnt));
Expand Down Expand Up @@ -1443,14 +1440,13 @@ void list_show_hidden(void)
{
set(app->LV_GenresList, MUIA_Disabled, TRUE);
filters.showHiddenOnly = TRUE;
showSlavesList();
}
else
{
set(app->LV_GenresList, MUIA_Disabled, FALSE);
filters.showHiddenOnly = FALSE;
showSlavesList();
}
showSlavesList();
}

void app_stop(void)
Expand Down Expand Up @@ -1768,9 +1764,10 @@ void non_whdload_ok(void)
set(app->LV_GamesList, MUIA_NList_Quiet, TRUE);
DoMethod(app->LV_GamesList,
MUIM_NList_InsertSingle, node,
MUIV_NList_Insert_Sorted);
MUIV_NList_Insert_Bottom);
get(app->LV_GamesList, MUIA_NList_InsertPosition, &newpos);
set(app->LV_GamesList, MUIA_NList_Active, newpos);
DoMethod(app->LV_GamesList, MUIM_NList_Sort);
set(app->LV_GamesList, MUIA_NList_Quiet, FALSE);
}

Expand Down
17 changes: 8 additions & 9 deletions src/iGameGUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,30 +191,30 @@ HOOKPROTONHNO(CompareLI_TextFunc, LONG, struct NList_CompareMessage *ncm)

if(ncm->sort_type == (LONG)MUIV_NList_SortType_None)
{
result = (LONG) Stricmp(entry1->title, entry2->title);
result = (LONG) strcmp(entry1->title, entry2->title);
return result;
}

if (column == 0)
{
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = (LONG) Stricmp(entry2->title, entry1->title);
result = (LONG) strcmp(entry2->title, entry1->title);
else
result = (LONG) Stricmp(entry1->title, entry2->title);
result = (LONG) strcmp(entry1->title, entry2->title);
}
else if (column == 1)
{
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = (LONG) Stricmp(entry2->year, entry1->year);
result = (LONG) strcmp(entry2->year, entry1->year);
else
result = (LONG) Stricmp(entry1->year, entry2->year);
result = (LONG) strcmp(entry1->year, entry2->year);
}
else if (column == 2)
{
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = (LONG) Stricmp(entry2->players, entry1->players);
result = (LONG) strcmp(entry2->players, entry1->players);
else
result = (LONG) Stricmp(entry1->players, entry2->players);
result = (LONG) strcmp(entry1->players, entry2->players);
}

// if (col1 == 0)
Expand Down Expand Up @@ -388,7 +388,7 @@ struct ObjApp *CreateApp(void)
MUIA_NList_TitleSeparator, TRUE,
MUIA_NList_Title, TRUE,
MUIA_NList_EntryValueDependent, FALSE,
MUIA_NList_MinColSortable, 0,
MUIA_NList_MinColSortable, 100,
MUIA_NList_Imports, MUIV_NList_Imports_Cols,
MUIA_NList_Exports, MUIV_NList_Exports_Cols,
End,
Expand Down Expand Up @@ -440,7 +440,6 @@ struct ObjApp *CreateApp(void)

object->LV_GenresList = ListObject,
MUIA_Frame, MUIV_Frame_InputList,
MUIA_List_Active, MUIV_List_Active_Top,
End;

object->LV_GenresList = ListviewObject,
Expand Down

0 comments on commit ad0cb1f

Please sign in to comment.