1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-03-13 09:10:07 +01:00

Optimize team_get_fixture()

When searching for a team's next fixture, only search in leagues that the team
is actually in.  This improves performance a lot in countries with many leagues.
I see about a 7x speed up simulating the first 6 weeks of English leagues using
billys_boots 2019/2020 definitions from the forums.
This commit is contained in:
Tom Stellard 2020-09-07 21:55:04 -07:00
parent 49236a28ac
commit 4696053c95
2 changed files with 22 additions and 0 deletions

View File

@ -280,6 +280,9 @@ team_get_fixture(const Team *tm, gboolean last_fixture)
if(!query_league_active(&lig(i))) if(!query_league_active(&lig(i)))
continue; continue;
if (!query_team_id_is_in_teams_array(tm, lig(i).teams))
continue;
for(j=0;j<lig(i).fixtures->len;j++) { for(j=0;j<lig(i).fixtures->len;j++) {
const Fixture *current_fixture = &g_array_index(lig(i).fixtures, Fixture, j); const Fixture *current_fixture = &g_array_index(lig(i).fixtures, Fixture, j);
if(current_fixture->attendance == -1 && if(current_fixture->attendance == -1 &&
@ -1180,6 +1183,22 @@ query_team_is_in_teams_array(const Team *tm, const GPtrArray *teams)
return FALSE; return FALSE;
} }
/** Same as query_team_is_in_teams_array, but it looks up based on the
* team id and not the pointer. This is useful, because you can look
* for a team in a GArray without having to transform it into a GPtrArray.
*/
gboolean
query_team_id_is_in_teams_array(const Team *tm, const GArray *teams)
{
gint i;
for (i = 0; i< teams->len; i++) {
const Team *t = &g_array_index(teams, Team, i);
if (t->id == tm->id)
return TRUE;
}
return FALSE;
}
/** Check whether we find a definition file for the /** Check whether we find a definition file for the
given team. */ given team. */
gchar* gchar*

View File

@ -145,6 +145,9 @@ team_write_own_results(const Team *tm, gchar *buf, gboolean sort, gboolean cup_m
gboolean gboolean
query_team_is_in_teams_array(const Team *tm, const GPtrArray *teams); query_team_is_in_teams_array(const Team *tm, const GPtrArray *teams);
gboolean
query_team_id_is_in_teams_array(const Team *tm, const GArray *teams);
gchar* gchar*
team_has_def_file(const Team *tm); team_has_def_file(const Team *tm);