diff options
author | Samuel Pitoiset <[email protected]> | 2017-05-29 17:26:30 +0200 |
---|---|---|
committer | Samuel Pitoiset <[email protected]> | 2017-06-14 10:04:35 +0200 |
commit | 30471eb7450b6a14f47f088ea3983ba86616db36 (patch) | |
tree | 99ea0941912aacc9819b462b670d6b87e0741cab /src | |
parent | 5f249b9f05ece03a7cbd591cdca0400cb619d11c (diff) |
mesa/util: add new util_dynarray_delete_unordered helper
This helper function will be used for managing dynamic arrays of
resident texture/image handles.
Signed-off-by: Samuel Pitoiset <[email protected]>
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/util/u_dynarray.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h index fdcd09c4bef..57f96ff79c0 100644 --- a/src/util/u_dynarray.h +++ b/src/util/u_dynarray.h @@ -138,6 +138,20 @@ util_dynarray_trim(struct util_dynarray *buf) for (type *elem = (type *)(buf)->data; \ elem < (type *)((char *)(buf)->data + (buf)->size); elem++) +#define util_dynarray_delete_unordered(buf, type, v) \ + do { \ + unsigned num_elements = (buf)->size / sizeof(type); \ + unsigned i; \ + for (i = 0; i < num_elements; i++) { \ + type __v = *util_dynarray_element((buf), type, (i)); \ + if (v == __v) { \ + memcpy(util_dynarray_element((buf), type, (i)), \ + util_dynarray_pop_ptr((buf), type), sizeof(type)); \ + break; \ + } \ + } \ + } while (0) + #ifdef __cplusplus } #endif |