aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-07-01 09:57:30 +0200
committerSimon Zeni <simon@bl4ckb0ne.ca>2021-07-01 10:35:39 -0400
commita6ed4ae3088fee654178dd063c77db108de890cd (patch)
tree4793665aa611b2d872b4e7d9c1e2b15605e84a85 /util
parentdbb0e2f75be0374724b0255b14bc72398d9907b5 (diff)
util/array: add array_remove_at
Diffstat (limited to 'util')
-rw-r--r--util/array.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/array.c b/util/array.c
index b708b577..50025b77 100644
--- a/util/array.c
+++ b/util/array.c
@@ -1,5 +1,6 @@
#include "util/array.h"
#include <assert.h>
+#include <string.h>
// https://www.geeksforgeeks.org/move-zeroes-end-array/
size_t push_zeroes_to_end(uint32_t arr[], size_t n) {
@@ -46,3 +47,11 @@ bool set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target) {
}
return false;
}
+
+void array_remove_at(struct wl_array *arr, size_t offset, size_t size) {
+ assert(arr->size >= offset + size);
+
+ char *data = arr->data;
+ memmove(&data[offset], &data[offset + size], arr->size - offset - size);
+ arr->size -= size;
+}