(PR#10321) Replace slow city_range_iterate
"Mateusz Stefek" <mstefek-IjDXvh/[email protected]>
| Newsgroups | gmane.games.freeciv.ai |
|---|---|
| Message-ID | <[email protected]> |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10321 > This patch replaces slow city_range_iterate macro with city_list_do It doesn't iterate over all cities if range == EFR_LOCAL or EFR_CITY Autogame times: Old: 2368.48user 82.32system New: 2403.24user 84.71system I don't have any idea why the new macro is slower. Per? -- mateusz
city_range_do.diff
(text/x-patch, 1.8 KB)
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.173
diff -u -r1.173 aicity.c
--- ai/aicity.c 24 Sep 2004 21:37:51 -0000 1.173
+++ ai/aicity.c 25 Sep 2004 11:00:06 -0000
@@ -72,6 +72,35 @@
|| pcity->food_stock + pcity->food_surplus < 0)
#define LOG_BUY LOG_DEBUG
+#define city_range_do(city_here, list, range, acity, action) \
+ switch(range) { \
+ case EFR_CITY: \
+ case EFR_LOCAL: \
+ { \
+ struct city* acity = city_here; \
+ action; \
+ break; \
+ } \
+ case EFR_PLAYER: \
+ { \
+ city_list_iterate(list, acity) { \
+ action; \
+ } city_list_iterate_end; \
+ break; \
+ } \
+ case EFR_CONTINENT: \
+ { \
+ Continent_id cont = map_get_continent(city_here->x, city_here->y);\
+ city_list_iterate(list, acity) { \
+ if (map_get_continent(acity->x, acity->y) == cont) { \
+ action; \
+ } \
+ } city_list_iterate_end; \
+ break; \
+ } \
+ default:; \
+ }
+
static void resolve_city_emergency(struct player *pplayer, struct city *pcity);
static void ai_sell_obsolete_buildings(struct city *pcity);
@@ -161,9 +190,8 @@
}
/* Stir, then compare notes */
- city_range_iterate(pcity, pplayer->cities, ai->impr_range[id], acity) {
- final_want += city_want(pplayer, acity, ai) - acity->ai.worth;
- } city_range_iterate_end;
+ city_range_do(pcity, pplayer->cities, ai->impr_range[id], acity,
+ final_want += city_want(pplayer, acity, ai) - acity->ai.worth);
/* Restore */
city_remove_improvement(pcity, id);