Skip to content

Commit ad0cb1f

Browse files
authored
Merge pull request #236 from walkero-gr/load-list-optimisations
Optimisation in list loading
2 parents e9b1509 + b76e366 commit ad0cb1f

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## iGame VERSION_TAG - [RELEASE_DATE]
22
### Changed
3+
- Some optimisation in list loading reducing the time needed more than 42%
4+
5+
## iGame 2.4.4 - [2023-09-11]
6+
### Changed
37
- Speedup the slavesListAddTail(), almost 200% faster. This has an impact on the slaves list creation during the scan and the loading from the file.
48

59
### Fixed

src/fsfuncs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,23 @@ BOOL get_filename(const char *title, const char *positive_text, const BOOL save_
176176

177177
void slavesListLoadFromCSV(char *filename)
178178
{
179-
int lineBufSize = sizeof(char) * 1024;
179+
int lineBufSize = sizeof(char) * 512;
180180

181181
if (check_path_exists(filename))
182182
{
183-
const BPTR fpgames = Open((CONST_STRPTR) filename, MODE_OLDFILE);
183+
FILE *fpgames = fopen(filename, "r");
184184
if (fpgames)
185185
{
186186
char *lineBuf = AllocVec(lineBufSize, MEMF_CLEAR);
187187
char *buf = AllocVec(sizeof(char) * MAX_PATH_SIZE, MEMF_CLEAR);
188188
if((buf == NULL) || (lineBuf == NULL))
189189
{
190190
msg_box((const char*)GetMBString(MSG_NotEnoughMemory));
191+
fclose(fpgames);
191192
return;
192193
}
193194

194-
while (FGets(fpgames, lineBuf, lineBufSize) != NULL)
195+
while (fgets(lineBuf, lineBufSize, fpgames) != NULL)
195196
{
196197
slavesList *node = malloc(sizeof(slavesList));
197198
if(node == NULL)
@@ -282,7 +283,7 @@ void slavesListLoadFromCSV(char *filename)
282283

283284
slavesListAddTail(node);
284285
}
285-
Close(fpgames);
286+
fclose(fpgames);
286287
FreeVec(lineBuf);
287288
}
288289
}

src/funcs.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static void populateGenresList(void)
308308
int cnt = 0;
309309
while (currPtr != NULL)
310310
{
311-
DoMethod(app->LV_GenresList, MUIM_List_InsertSingle, currPtr->title, MUIV_List_Insert_Sorted);
311+
DoMethod(app->LV_GenresList, MUIM_List_InsertSingle, currPtr->title, MUIV_List_Insert_Bottom);
312312

313313
cnt++;
314314
currPtr = currPtr->next;
@@ -323,6 +323,8 @@ static void populateGenresList(void)
323323
app->CY_PropertiesGenreContent[i++] = NULL;
324324
set(app->CY_PropertiesGenre, MUIA_Cycle_Entries, app->CY_PropertiesGenreContent);
325325
set(app->CY_AddGameGenre, MUIA_Cycle_Entries, app->CY_PropertiesGenreContent);
326+
set(app->LV_GenresList, MUIA_List_Active, MUIV_List_Active_Top);
327+
DoMethod(app->LV_GenresList, MUIM_List_Sort);
326328
set(app->LV_GenresList, MUIA_List_Quiet, FALSE);
327329
}
328330

@@ -360,7 +362,6 @@ void app_start(void)
360362
load_repos(DEFAULT_REPOS_FILE);
361363
apply_settings();
362364

363-
364365
if (current_settings->start_with_favorites)
365366
{
366367
filters.showGroup = GROUP_FAVOURITES;
@@ -381,7 +382,7 @@ void app_start(void)
381382

382383
if (!current_settings->hide_side_panel)
383384
{
384-
populateGenresList();
385+
populateGenresList(); // This calls the filter_change()
385386
populateChipsetList();
386387
}
387388
if (current_settings->hide_side_panel)
@@ -682,19 +683,14 @@ static void showSlavesList(void)
682683
{
683684
if (currPtr->times_played < mostPlayedTimes)
684685
{
685-
// DoMethod(app->LV_GamesList,
686-
// MUIM_List_InsertSingle, currPtr->title,
687-
// MUIV_List_Insert_Bottom);
688686
DoMethod(app->LV_GamesList,
689687
MUIM_NList_InsertSingle, currPtr,
690688
MUIV_NList_Insert_Bottom);
691689
}
692690
else
693691
{
694692
mostPlayedTimes = currPtr->times_played;
695-
// DoMethod(app->LV_GamesList,
696-
// MUIM_List_InsertSingle, currPtr->title,
697-
// MUIV_List_Insert_Top);
693+
698694
DoMethod(app->LV_GamesList,
699695
MUIM_NList_InsertSingle, currPtr,
700696
MUIV_NList_Insert_Top);
@@ -713,14 +709,15 @@ static void showSlavesList(void)
713709

714710
DoMethod(app->LV_GamesList,
715711
MUIM_NList_InsertSingle, currPtr,
716-
MUIV_NList_Insert_Sorted);
712+
MUIV_NList_Insert_Bottom);
717713

718714
cnt++;
719715
nextItem:
720716
}
721717

722718
currPtr = currPtr->next;
723719
}
720+
DoMethod(app->LV_GamesList, MUIM_NList_Sort);
724721
set(app->LV_GamesList, MUIA_NList_Quiet, FALSE);
725722

726723
sprintf(buf, (const char *)GetMBString(MSG_TotalNumberOfGames), slavesListNodeCount(cnt));
@@ -1443,14 +1440,13 @@ void list_show_hidden(void)
14431440
{
14441441
set(app->LV_GenresList, MUIA_Disabled, TRUE);
14451442
filters.showHiddenOnly = TRUE;
1446-
showSlavesList();
14471443
}
14481444
else
14491445
{
14501446
set(app->LV_GenresList, MUIA_Disabled, FALSE);
14511447
filters.showHiddenOnly = FALSE;
1452-
showSlavesList();
14531448
}
1449+
showSlavesList();
14541450
}
14551451

14561452
void app_stop(void)
@@ -1768,9 +1764,10 @@ void non_whdload_ok(void)
17681764
set(app->LV_GamesList, MUIA_NList_Quiet, TRUE);
17691765
DoMethod(app->LV_GamesList,
17701766
MUIM_NList_InsertSingle, node,
1771-
MUIV_NList_Insert_Sorted);
1767+
MUIV_NList_Insert_Bottom);
17721768
get(app->LV_GamesList, MUIA_NList_InsertPosition, &newpos);
17731769
set(app->LV_GamesList, MUIA_NList_Active, newpos);
1770+
DoMethod(app->LV_GamesList, MUIM_NList_Sort);
17741771
set(app->LV_GamesList, MUIA_NList_Quiet, FALSE);
17751772
}
17761773

src/iGameGUI.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,30 @@ HOOKPROTONHNO(CompareLI_TextFunc, LONG, struct NList_CompareMessage *ncm)
191191

192192
if(ncm->sort_type == (LONG)MUIV_NList_SortType_None)
193193
{
194-
result = (LONG) Stricmp(entry1->title, entry2->title);
194+
result = (LONG) strcmp(entry1->title, entry2->title);
195195
return result;
196196
}
197197

198198
if (column == 0)
199199
{
200200
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
201-
result = (LONG) Stricmp(entry2->title, entry1->title);
201+
result = (LONG) strcmp(entry2->title, entry1->title);
202202
else
203-
result = (LONG) Stricmp(entry1->title, entry2->title);
203+
result = (LONG) strcmp(entry1->title, entry2->title);
204204
}
205205
else if (column == 1)
206206
{
207207
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
208-
result = (LONG) Stricmp(entry2->year, entry1->year);
208+
result = (LONG) strcmp(entry2->year, entry1->year);
209209
else
210-
result = (LONG) Stricmp(entry1->year, entry2->year);
210+
result = (LONG) strcmp(entry1->year, entry2->year);
211211
}
212212
else if (column == 2)
213213
{
214214
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
215-
result = (LONG) Stricmp(entry2->players, entry1->players);
215+
result = (LONG) strcmp(entry2->players, entry1->players);
216216
else
217-
result = (LONG) Stricmp(entry1->players, entry2->players);
217+
result = (LONG) strcmp(entry1->players, entry2->players);
218218
}
219219

220220
// if (col1 == 0)
@@ -388,7 +388,7 @@ struct ObjApp *CreateApp(void)
388388
MUIA_NList_TitleSeparator, TRUE,
389389
MUIA_NList_Title, TRUE,
390390
MUIA_NList_EntryValueDependent, FALSE,
391-
MUIA_NList_MinColSortable, 0,
391+
MUIA_NList_MinColSortable, 100,
392392
MUIA_NList_Imports, MUIV_NList_Imports_Cols,
393393
MUIA_NList_Exports, MUIV_NList_Exports_Cols,
394394
End,
@@ -440,7 +440,6 @@ struct ObjApp *CreateApp(void)
440440

441441
object->LV_GenresList = ListObject,
442442
MUIA_Frame, MUIV_Frame_InputList,
443-
MUIA_List_Active, MUIV_List_Active_Top,
444443
End;
445444

446445
object->LV_GenresList = ListviewObject,

0 commit comments

Comments
 (0)