summaryrefslogtreecommitdiff
path: root/src/darray.h
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-09-22 02:05:48 +0300
committerDaniel Stone <daniel@fooishbar.org>2012-09-24 09:08:54 +1000
commit428c6f313fe1184d95248b57257a34f339bb0b6d (patch)
treeaa7396a09dbcb117e1ce3931eccd24a6801f6afb /src/darray.h
parentf671ce07ff58c7685a6bec9ba0faf3227907681d (diff)
downloadxorg-lib-libxkbcommon-428c6f313fe1184d95248b57257a34f339bb0b6d.tar.gz
symbols: convert KeyInfo->groups to darray
Before it was a static array of size XKB_NUM_GROUPS. The previous cleanups made this transition a bit easier. This is a first step for removing the XKB_NUM_GROUPS hardcoded limit; but for now we still check that the groups are < XKB_NUM_GROUPS (e.g. in ResolveGroup and GetGroupIndex) until the keymap, etc. is worked out as well. This also makes us alloc quite a bit less (this is just rulescomp): Before: ==51999== total heap usage: 291,474 allocs, 291,474 frees, 21,458,334 bytes allocated After: ==31394== total heap usage: 293,595 allocs, 293,595 frees, 18,150,110 bytes allocated This is because most rmlvo's don't use the full 4 layouts that KeyInfo had always alloced statically before. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/darray.h')
-rw-r--r--src/darray.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/darray.h b/src/darray.h
index c9b6094..569576e 100644
--- a/src/darray.h
+++ b/src/darray.h
@@ -326,6 +326,17 @@ darray_next_alloc(size_t alloc, size_t need)
#define darray_foreach_from(i, arr, from) \
for ((i) = &(arr).item[from]; (i) < &(arr).item[(arr).size]; (i)++)
+/* Iterate on index and value at the same time, like Python's enumerate. */
+#define darray_enumerate(idx, val, arr) \
+ for ((idx) = 0, (val) = &(arr).item[0]; \
+ (idx) < (arr).size; \
+ (idx)++, (val)++)
+
+#define darray_enumerate_from(idx, val, arr, from) \
+ for ((idx) = (from), (val) = &(arr).item[0]; \
+ (idx) < (arr).size; \
+ (idx)++, (val)++)
+
/*
* darray_foreach_reverse(T *&i, darray(T) arr) {...}
*