From a6ed4ae3088fee654178dd063c77db108de890cd Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 1 Jul 2021 09:57:30 +0200 Subject: util/array: add array_remove_at --- util/array.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'util') 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 +#include // 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; +} -- cgit v1.2.3