Author: cazfi
Date: Thu Oct  1 06:12:55 2015
New Revision: 30006

URL: http://svn.gna.org/viewcvs/freeciv?rev=30006&view=rev
Log:
Minor map_pos_to_tile() optimizations.

See patch #6380

Modified:
    trunk/common/map.c
    trunk/common/map.h

Modified: trunk/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.c?rev=30006&r1=30005&r2=30006&view=diff
==============================================================================
--- trunk/common/map.c  (original)
+++ trunk/common/map.c  Thu Oct  1 06:12:55 2015
@@ -396,7 +396,8 @@
     return NULL;
   }
 
-  return map.tiles + native_pos_to_index(nat_x, nat_y);
+  /* We already checked legality of native pos above, don't repeat */
+  return map.tiles + native_pos_to_index_nocheck(nat_x, nat_y);
 }
 
 /****************************************************************************
@@ -404,7 +405,12 @@
 ****************************************************************************/
 struct tile *map_pos_to_tile(int map_x, int map_y)
 {
-  int nat_x, nat_y;
+  /* Instead of introducing new variables for native coordinates,
+   * update the map coordinate variables = registers already in use.
+   * This is one of the most performance-critical functions we have,
+   * so taking measures like this makes sense. */
+#define nat_x map_x
+#define nat_y map_y
 
   if (!map.tiles) {
     return NULL;
@@ -413,6 +419,9 @@
   /* Normalization is best done in native coordinates. */
   MAP_TO_NATIVE_POS(&nat_x, &nat_y, map_x, map_y);
   return base_native_pos_to_tile(nat_x, nat_y);
+
+#undef nat_x
+#undef nat_y
 }
 
 /****************************************************************************

Modified: trunk/common/map.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.h?rev=30006&r1=30005&r2=30006&view=diff
==============================================================================
--- trunk/common/map.h  (original)
+++ trunk/common/map.h  Thu Oct  1 06:12:55 2015
@@ -119,7 +119,7 @@
 static const bool C_NUMBER = FALSE;
 static const bool C_PERCENT = TRUE;
 
-#define MAP_IS_ISOMETRIC (current_topo_has_flag(TF_ISO) || 
current_topo_has_flag(TF_HEX))
+#define MAP_IS_ISOMETRIC (CURRENT_TOPOLOGY & (TF_ISO + TF_HEX))
 
 #define CURRENT_TOPOLOGY (map.topology_id)
 
@@ -219,9 +219,11 @@
 #define CHECK_INDEX(index) ((void)0)
 #endif
 
+#define native_pos_to_index_nocheck(nat_x, nat_y)                            \
+  ((nat_x) + (nat_y) * map.xsize)
 #define native_pos_to_index(nat_x, nat_y)                                    \
   (CHECK_NATIVE_POS((nat_x), (nat_y)),                                       \
-   (nat_x) + (nat_y) * map.xsize)
+   native_pos_to_index_nocheck(nat_x, nat_y))
 #define index_to_native_pos(pnat_x, pnat_y, index)                           \
   (*(pnat_x) = index_to_native_pos_x(index),                                 \
    *(pnat_y) = index_to_native_pos_y(index))


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to