town_gui.c
changeset 1260 c60e76928e5c
parent 1093 e8d26c7dc42f
child 1299 0a6510cc889b
--- a/town_gui.c	Tue Feb 01 18:30:11 2005 +0000
+++ b/town_gui.c	Tue Feb 01 18:32:01 2005 +0000
@@ -367,14 +367,18 @@
 {
 	char buf1[64];
 	const Town *t;
-	byte val;
+	uint16 val;
 	int r;
 
 	t = GetTown(*(const uint16*)a);
 	SetDParam(0, t->townnameparts);
 	GetString(buf1, t->townnametype);
 
-	if ( (val=*(const uint16*)b) != _last_town_idx) {
+	/* If 'b' is the same town as in the last round, use the cached value
+	 *  We do this to speed stuff up ('b' is called with the same value a lot of
+	*  times after eachother) */
+	val = *(const uint16*)b;
+	if (val != _last_town_idx) {
 		_last_town_idx = val;
 		t = GetTown(val);
 		SetDParam(0, t->townnameparts);
@@ -401,12 +405,12 @@
 	int n = 0;
 
 	/* Create array for sorting */
-	_town_sort = realloc(_town_sort, _towns_size * sizeof(_town_sort[0]));
+	_town_sort = realloc(_town_sort, GetTownPoolSize() * sizeof(_town_sort[0]));
 	if (_town_sort == NULL)
 		error("Could not allocate memory for the town-sorting-list");
 
 	FOR_ALL_TOWNS(t)
-		if(t->xy)
+		if (t->xy)
 			_town_sort[n++] = t->index;
 
 	_num_town_sort = n;