[freeciv-ai] (PR#10321) Replace slow city_range_iterate
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[freeciv-ai] (PR#10321) Replace slow city_range_iterate |
From: |
"Mateusz Stefek" <mstefek@xxxxxxxxx> |
Date: |
Sat, 25 Sep 2004 04:35:06 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<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
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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freeciv-ai] (PR#10321) Replace slow city_range_iterate,
Mateusz Stefek <=
|
|