mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
mapper: place strings in array
mapper: place strings in a big array. Make it possible to configure array and map extend size.
This commit is contained in:
parent
f613240b66
commit
d9a51b5d14
10 changed files with 41 additions and 25 deletions
|
|
@ -32,8 +32,11 @@ struct _PinosArray {
|
|||
void *data;
|
||||
size_t size;
|
||||
size_t alloc;
|
||||
size_t extend;
|
||||
};
|
||||
|
||||
#define PINOS_ARRAY_INIT(extend) { NULL, 0, 0, extend }
|
||||
|
||||
#define pinos_array_get_len_s(a,s) ((a)->size / (s))
|
||||
#define pinos_array_get_unchecked_s(a,idx,s,t) SPA_MEMBER ((a)->data,(idx)*(s),t)
|
||||
#define pinos_array_check_index_s(a,idx,s) ((idx) < pinos_array_get_len(a,s))
|
||||
|
|
@ -48,10 +51,11 @@ struct _PinosArray {
|
|||
(pos)++)
|
||||
|
||||
static inline void
|
||||
pinos_array_init (PinosArray *arr)
|
||||
pinos_array_init (PinosArray *arr, size_t extend)
|
||||
{
|
||||
arr->data = NULL;
|
||||
arr->size = arr->alloc = 0;
|
||||
arr->extend = extend;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -71,7 +75,7 @@ pinos_array_ensure_size (PinosArray *arr,
|
|||
|
||||
if (SPA_UNLIKELY (alloc < need)) {
|
||||
void *data;
|
||||
alloc = SPA_MAX (alloc, 16);
|
||||
alloc = SPA_MAX (alloc, arr->extend);
|
||||
while (alloc < need)
|
||||
alloc *= 2;
|
||||
if (SPA_UNLIKELY ((data = realloc (arr->data, alloc)) == NULL))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue