Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8683) specvec iterator patch v2
Home

[Freeciv-Dev] (PR#8683) specvec iterator patch v2

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#8683) specvec iterator patch v2
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Fri, 14 May 2004 19:22:17 -0700
Reply-to: rt@xxxxxxxxxxx

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

> [vasc - Sat May 15 02:11:49 2004]:
> 
> An iterator macro patch for specvec.

On second thought, it is better to pass a pointer to the element. This
way you can do a write to the current element as well and is faster than
doing a copy for vectors with large element types (i.e. structs).

Index: utility/specvec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/specvec.h,v
retrieving revision 1.5
diff -u -r1.5 specvec.h
--- utility/specvec.h   15 May 2004 00:48:17 -0000      1.5
+++ utility/specvec.h   15 May 2004 02:19:45 -0000
@@ -130,6 +130,17 @@
   SPECVEC_FOO(_vector_init)(tthis);
 }
 
+
+#define TYPED_VECTOR_ITERATE(atype, vector, var) {      \
+  int myiter;                                          \
+  atype *var;                                           \
+  for (myiter = 0; myiter < (vector)->size; myiter++) { \
+    var = &(vector)->p[myiter];                                \
+ 
+/* Balance for above: */
+#define VECTOR_ITERATE_END  }}
+
+
 #undef SPECVEC_TAG
 #undef SPECVEC_TYPE
 #undef SPECVEC_PASTE_

[Prev in Thread] Current Thread [Next in Thread]