dovecot-2.0: Added array_foreach() and array_foreach_modifiable().
dovecot at dovecot.org
dovecot at dovecot.org
Thu Oct 8 09:54:55 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/ada435a92e93
changeset: 9996:ada435a92e93
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 08 02:54:45 2009 -0400
description:
Added array_foreach() and array_foreach_modifiable().
diffstat:
1 file changed, 25 insertions(+)
src/lib/array.h | 25 +++++++++++++++++++++++++
diffs (35 lines):
diff -r c20d6f518451 -r ada435a92e93 src/lib/array.h
--- a/src/lib/array.h Thu Oct 08 01:37:57 2009 -0400
+++ b/src/lib/array.h Thu Oct 08 02:54:45 2009 -0400
@@ -53,6 +53,31 @@
# define ARRAY_TYPE_CHECK(array, data) 0
#endif
+/* usage: struct foo *foo; array_foreach(foo_arr, foo) { .. } */
+#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L)
+# define array_foreach(array, elem) \
+ for (const void *elem ## __foreach_end = \
+ (const char *)(elem = *(array)->v) + (array)->arr.buffer->used; \
+ elem != elem ## __foreach_end; (elem)++)
+# define array_foreach_modifiable(array, elem) \
+ for (const void *elem ## _end = \
+ (const char *)(elem = ARRAY_TYPE_CAST_MODIFIABLE(array) \
+ buffer_get_modifiable_data((array)->arr.buffer, NULL)) + \
+ (array)->arr.buffer->used; \
+ elem != elem ## _end; elem++)
+#else
+# define array_foreach(array, elem) \
+ for (elem = *(array)->v; \
+ elem != CONST_PTR_OFFSET(*(array)->v, (array)->arr.buffer->used); \
+ (elem)++)
+# define array_foreach_modifiable(array, elem) \
+ for (elem = ARRAY_TYPE_CAST_MODIFIABLE(array) \
+ buffer_get_modifiable_data((array)->arr.buffer, NULL)) + \
+ (array)->arr.buffer->used; \
+ elem != CONST_PTR_OFFSET(*(array)->v, (array)->arr.buffer->used); \
+ (elem)++)
+#endif
+
static inline void
array_create_from_buffer_i(struct array *array, buffer_t *buffer,
size_t element_size)
More information about the dovecot-cvs
mailing list