mirror of
https://github.com/tstellar/bygfoot.git
synced 2025-03-13 01:00:15 +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:
parent
49236a28ac
commit
4696053c95
19
src/team.c
19
src/team.c
@ -280,6 +280,9 @@ team_get_fixture(const Team *tm, gboolean last_fixture)
|
||||
if(!query_league_active(&lig(i)))
|
||||
continue;
|
||||
|
||||
if (!query_team_id_is_in_teams_array(tm, lig(i).teams))
|
||||
continue;
|
||||
|
||||
for(j=0;j<lig(i).fixtures->len;j++) {
|
||||
const Fixture *current_fixture = &g_array_index(lig(i).fixtures, Fixture, j);
|
||||
if(current_fixture->attendance == -1 &&
|
||||
@ -1180,6 +1183,22 @@ query_team_is_in_teams_array(const Team *tm, const GPtrArray *teams)
|
||||
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
|
||||
given team. */
|
||||
gchar*
|
||||
|
@ -145,6 +145,9 @@ team_write_own_results(const Team *tm, gchar *buf, gboolean sort, gboolean cup_m
|
||||
gboolean
|
||||
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*
|
||||
team_has_def_file(const Team *tm);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user