Merge branch 'main' into 'main'

util: Add wl_array_remove_at function

See merge request wayland/wayland!261
This commit is contained in:
Petro Mozil 2025-09-16 15:44:44 +00:00
commit 2a173d80a4
2 changed files with 21 additions and 0 deletions

View file

@ -138,6 +138,16 @@ wl_array_add(struct wl_array *array, size_t size)
return p;
}
WL_EXPORT void
wl_array_remove_at(struct wl_array *array, size_t offset, size_t size) {
if (array->size < offset + size)
wl_abort("Cannot remove data: array of size %zu is smaller than %zu", array->size, offset+size);
char *data = array->data;
memmove(&data[offset], &data[offset+size], array->size - offset - size);
array->size -= size;
}
WL_EXPORT int
wl_array_copy(struct wl_array *array, struct wl_array *source)
{

View file

@ -576,7 +576,18 @@ wl_array_release(struct wl_array *array);
*/
void *
wl_array_add(struct wl_array *array, size_t size);
/**
* Removes a chunk of the specified size at the specified offset
*
* \param array Array whose data is to be removed
* \param offset Offset to remove data at
* \param size Size of data to be removed
*
* \memberof wl_array
*/
void
wl_array_remove_at(struct wl_array *array, size_t offset, size_t size);
/**
* Copies the contents of \p source to \p array.
*