Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8551) rewrite adjc_iterate
Home

[Freeciv-Dev] (PR#8551) rewrite adjc_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8551) rewrite adjc_iterate
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Apr 2004 22:56:18 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8551 >

This patch rewrites adjc_iterate to be a wrapper for adjc_dir_iterate. 
This is cleaner and may be marginally faster (my tests showed a slight 
decrease in runtime, but I'm not sure it's statistically significant).

Some years ago adjc_iterate was rewritten from its original form into 
the current form, which is a wrapper for square_iterate.  However 
writing it as a wrapper for adjc_dir_iterate seems better.

jason

? common/output
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.177
diff -u -r1.177 map.h
--- common/map.h        26 Feb 2004 13:19:47 -0000      1.177
+++ common/map.h        20 Apr 2004 05:55:15 -0000
@@ -465,16 +465,16 @@
   } square_dxy_iterate_end;                                                   \
 }                                                                             
 
-/* Iterate through all tiles adjacent to a tile */
-#define adjc_iterate(RI_center_x, RI_center_y, RI_x_itr, RI_y_itr)            \
+/* Iterate through all map positions adjacent to the given center map
+ * position, with normalization.  The order of positions is unspecified. */
+#define adjc_iterate(center_x, center_y, x_itr, y_itr)                        \
 {                                                                             \
-  square_iterate(RI_center_x, RI_center_y, 1, RI_x_itr, RI_y_itr) {           \
-    if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y) {                 \
-      continue;                                                               \
-    }
+  /* Written as a wrapper to adjc_dir_iterate since it's the cleanest and     \
+   * most efficient. */                                                       \
+  adjc_dir_iterate(center_x, center_y, x_itr, y_itr, ADJC_ITERATE_dir_itr) {
 
 #define adjc_iterate_end                                                      \
-  } square_iterate_end;                                                       \
+  } adjc_dir_iterate_end;                                                     \
 }
 
 /* Iterate through all tiles adjacent to a tile.  dir_itr is the

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8551) rewrite adjc_iterate, Jason Short <=