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;
|
void *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t alloc;
|
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_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_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))
|
#define pinos_array_check_index_s(a,idx,s) ((idx) < pinos_array_get_len(a,s))
|
||||||
|
|
@ -48,10 +51,11 @@ struct _PinosArray {
|
||||||
(pos)++)
|
(pos)++)
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
pinos_array_init (PinosArray *arr)
|
pinos_array_init (PinosArray *arr, size_t extend)
|
||||||
{
|
{
|
||||||
arr->data = NULL;
|
arr->data = NULL;
|
||||||
arr->size = arr->alloc = 0;
|
arr->size = arr->alloc = 0;
|
||||||
|
arr->extend = extend;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|
@ -71,7 +75,7 @@ pinos_array_ensure_size (PinosArray *arr,
|
||||||
|
|
||||||
if (SPA_UNLIKELY (alloc < need)) {
|
if (SPA_UNLIKELY (alloc < need)) {
|
||||||
void *data;
|
void *data;
|
||||||
alloc = SPA_MAX (alloc, 16);
|
alloc = SPA_MAX (alloc, arr->extend);
|
||||||
while (alloc < need)
|
while (alloc < need)
|
||||||
alloc *= 2;
|
alloc *= 2;
|
||||||
if (SPA_UNLIKELY ((data = realloc (arr->data, alloc)) == NULL))
|
if (SPA_UNLIKELY ((data = realloc (arr->data, alloc)) == NULL))
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ again:
|
||||||
*dt = buf->data;
|
*dt = buf->data;
|
||||||
*sz = buf->size;
|
*sz = buf->size;
|
||||||
|
|
||||||
spa_debug_pod (data);
|
// spa_debug_pod (data);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -310,7 +310,7 @@ pinos_connection_end_write (PinosConnection *conn,
|
||||||
|
|
||||||
buf->buffer_size += 8 + size;
|
buf->buffer_size += 8 + size;
|
||||||
|
|
||||||
spa_debug_pod (p);
|
// spa_debug_pod (p);
|
||||||
|
|
||||||
pinos_signal_emit (&conn->need_flush, conn);
|
pinos_signal_emit (&conn->need_flush, conn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -486,8 +486,8 @@ pinos_context_new (PinosLoop *loop,
|
||||||
|
|
||||||
this->state = PINOS_CONTEXT_STATE_UNCONNECTED;
|
this->state = PINOS_CONTEXT_STATE_UNCONNECTED;
|
||||||
|
|
||||||
pinos_map_init (&this->objects, 64);
|
pinos_map_init (&this->objects, 64, 32);
|
||||||
pinos_map_init (&this->uris, 64);
|
pinos_map_init (&this->uris, 64, 32);
|
||||||
|
|
||||||
spa_list_init (&this->stream_list);
|
spa_list_init (&this->stream_list);
|
||||||
spa_list_init (&this->global_list);
|
spa_list_init (&this->global_list);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ struct _PinosMap {
|
||||||
uint32_t free_list;
|
uint32_t free_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define PINOS_MAP_INIT(extend) { PINOS_ARRAY_INIT(extend), 0 }
|
||||||
|
|
||||||
#define pinos_map_get_size(m) pinos_array_get_len (&(m)->items, PinosMapItem)
|
#define pinos_map_get_size(m) pinos_array_get_len (&(m)->items, PinosMapItem)
|
||||||
#define pinos_map_get_item(m,id) pinos_array_get_unchecked(&(m)->items,id,PinosMapItem)
|
#define pinos_map_get_item(m,id) pinos_array_get_unchecked(&(m)->items,id,PinosMapItem)
|
||||||
#define pinos_map_item_is_free(item) ((item)->next & 0x1)
|
#define pinos_map_item_is_free(item) ((item)->next & 0x1)
|
||||||
|
|
@ -53,9 +55,10 @@ struct _PinosMap {
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
pinos_map_init (PinosMap *map,
|
pinos_map_init (PinosMap *map,
|
||||||
size_t size)
|
size_t size,
|
||||||
|
size_t extend)
|
||||||
{
|
{
|
||||||
pinos_array_init (&map->items);
|
pinos_array_init (&map->items, extend);
|
||||||
pinos_array_ensure_size (&map->items, size * sizeof (PinosMapItem));
|
pinos_array_ensure_size (&map->items, size * sizeof (PinosMapItem));
|
||||||
map->free_list = 0;
|
map->free_list = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,25 +27,31 @@
|
||||||
|
|
||||||
#include <pinos/client/map.h>
|
#include <pinos/client/map.h>
|
||||||
|
|
||||||
#define MAX_URIS 4096
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SpaIDMap map;
|
SpaIDMap map;
|
||||||
PinosMap uris;
|
PinosMap uris;
|
||||||
|
PinosArray strings;
|
||||||
} IDMap;
|
} IDMap;
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
id_map_get_id (SpaIDMap *map, const char *uri)
|
id_map_get_id (SpaIDMap *map, const char *uri)
|
||||||
{
|
{
|
||||||
IDMap *this = SPA_CONTAINER_OF (map, IDMap, map);
|
IDMap *this = SPA_CONTAINER_OF (map, IDMap, map);
|
||||||
uint32_t i = 0;
|
uint32_t i = 0, len;
|
||||||
|
void *p;
|
||||||
|
off_t o;
|
||||||
|
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
for (i = 0; i < pinos_map_get_size (&this->uris); i++) {
|
for (i = 0; i < pinos_map_get_size (&this->uris); i++) {
|
||||||
if (strcmp (pinos_map_lookup_unchecked (&this->uris, i), uri) == 0)
|
o = (off_t) pinos_map_lookup_unchecked (&this->uris, i);
|
||||||
|
if (strcmp (SPA_MEMBER (this->strings.data, o, char), uri) == 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
i = pinos_map_insert_new (&this->uris, strdup (uri));
|
len = strlen (uri);
|
||||||
|
p = pinos_array_add (&this->strings, SPA_ROUND_UP_N (len+1, 2));
|
||||||
|
memcpy (p, uri, len+1);
|
||||||
|
o = (p - this->strings.data);
|
||||||
|
i = pinos_map_insert_new (&this->uris, (void *)o);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
@ -54,12 +60,14 @@ static const char *
|
||||||
id_map_get_uri (SpaIDMap *map, uint32_t id)
|
id_map_get_uri (SpaIDMap *map, uint32_t id)
|
||||||
{
|
{
|
||||||
IDMap *this = SPA_CONTAINER_OF (map, IDMap, map);
|
IDMap *this = SPA_CONTAINER_OF (map, IDMap, map);
|
||||||
|
|
||||||
if (id == SPA_ID_INVALID)
|
if (id == SPA_ID_INVALID)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (SPA_LIKELY (pinos_map_check_id (&this->uris, id)))
|
if (SPA_LIKELY (pinos_map_check_id (&this->uris, id))) {
|
||||||
return pinos_map_lookup_unchecked (&this->uris, id);
|
off_t o = (off_t) pinos_map_lookup_unchecked (&this->uris, id);
|
||||||
|
return SPA_MEMBER (this->strings.data, o, char);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +85,8 @@ static IDMap default_id_map = {
|
||||||
id_map_get_uri,
|
id_map_get_uri,
|
||||||
id_map_get_size,
|
id_map_get_size,
|
||||||
},
|
},
|
||||||
{ { NULL, } },
|
PINOS_MAP_INIT(128),
|
||||||
|
PINOS_ARRAY_INIT (4096)
|
||||||
};
|
};
|
||||||
|
|
||||||
SpaIDMap *
|
SpaIDMap *
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ pinos_properties_new (const char *key, ...)
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pinos_array_init (&impl->items);
|
pinos_array_init (&impl->items, 16);
|
||||||
|
|
||||||
va_start (varargs, key);
|
va_start (varargs, key);
|
||||||
while (key != NULL) {
|
while (key != NULL) {
|
||||||
|
|
@ -112,7 +112,7 @@ pinos_properties_new_dict (const SpaDict *dict)
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pinos_array_init (&impl->items);
|
pinos_array_init (&impl->items, 16);
|
||||||
|
|
||||||
for (i = 0; i < dict->n_items; i++)
|
for (i = 0; i < dict->n_items; i++)
|
||||||
add_func (&impl->this, strdup (dict->items[i].key), strdup (dict->items[i].value));
|
add_func (&impl->this, strdup (dict->items[i].key), strdup (dict->items[i].value));
|
||||||
|
|
|
||||||
|
|
@ -225,9 +225,9 @@ pinos_stream_new (PinosContext *context,
|
||||||
this->state = PINOS_STREAM_STATE_UNCONNECTED;
|
this->state = PINOS_STREAM_STATE_UNCONNECTED;
|
||||||
|
|
||||||
impl->node_state = SPA_NODE_STATE_INIT;
|
impl->node_state = SPA_NODE_STATE_INIT;
|
||||||
pinos_array_init (&impl->mem_ids);
|
pinos_array_init (&impl->mem_ids, 64);
|
||||||
pinos_array_ensure_size (&impl->mem_ids, sizeof (MemId) * 64);
|
pinos_array_ensure_size (&impl->mem_ids, sizeof (MemId) * 64);
|
||||||
pinos_array_init (&impl->buffer_ids);
|
pinos_array_init (&impl->buffer_ids, 32);
|
||||||
pinos_array_ensure_size (&impl->buffer_ids, sizeof (BufferId) * 64);
|
pinos_array_ensure_size (&impl->buffer_ids, sizeof (BufferId) * 64);
|
||||||
impl->pending_seq = SPA_ID_INVALID;
|
impl->pending_seq = SPA_ID_INVALID;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ pinos_split_strv (const char *str,
|
||||||
size_t len;
|
size_t len;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
pinos_array_init (&arr);
|
pinos_array_init (&arr, 16);
|
||||||
|
|
||||||
s = pinos_split_walk (str, delimiter, &len, &state);
|
s = pinos_split_walk (str, delimiter, &len, &state);
|
||||||
while (s && n + 1 < max_tokens) {
|
while (s && n + 1 < max_tokens) {
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,8 @@ pinos_client_new (PinosCore *core,
|
||||||
pinos_signal_init (&this->resource_added);
|
pinos_signal_init (&this->resource_added);
|
||||||
pinos_signal_init (&this->resource_removed);
|
pinos_signal_init (&this->resource_removed);
|
||||||
|
|
||||||
pinos_map_init (&this->objects, 0);
|
pinos_map_init (&this->objects, 0, 32);
|
||||||
pinos_map_init (&this->uris, 0);
|
pinos_map_init (&this->uris, 0, 32);
|
||||||
pinos_signal_init (&this->destroy_signal);
|
pinos_signal_init (&this->destroy_signal);
|
||||||
|
|
||||||
spa_list_insert (core->client_list.prev, &this->link);
|
spa_list_insert (core->client_list.prev, &this->link);
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ pinos_core_new (PinosMainLoop *main_loop,
|
||||||
|
|
||||||
pinos_uri_init (&this->uri);
|
pinos_uri_init (&this->uri);
|
||||||
pinos_access_init (&this->access);
|
pinos_access_init (&this->access);
|
||||||
pinos_map_init (&this->objects, 512);
|
pinos_map_init (&this->objects, 128, 32);
|
||||||
|
|
||||||
impl->support[0].uri = SPA_ID_MAP_URI;
|
impl->support[0].uri = SPA_ID_MAP_URI;
|
||||||
impl->support[0].data = this->uri.map;
|
impl->support[0].data = this->uri.map;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue