util: Add macro to get number of elements in dynarray
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 12 Sep 2018 22:21:20 +0000 (15:21 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Fri, 21 Sep 2018 17:12:51 +0000 (10:12 -0700)
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
src/util/u_dynarray.h

index 6bea481d44bfe591a9902b7a8b2fd93c93ca2616..512c0efc76272a6f2747e8618a14c79a5ab335ce 100644 (file)
@@ -149,6 +149,7 @@ util_dynarray_trim(struct util_dynarray *buf)
 #define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx))
 #define util_dynarray_begin(buf) ((buf)->data)
 #define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size))
+#define util_dynarray_num_elements(buf, type) ((buf)->size / sizeof(type))
 
 #define util_dynarray_foreach(buf, type, elem) \
    for (type *elem = (type *)(buf)->data; \