mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-06-05 03:01:53 -04:00
pipewire: properties: add helper to find item directly
Add find_item() which retrieves a spa_dict_item directly, and delete find_index() as it is no longer needed.
This commit is contained in:
parent
ab4de7733f
commit
2088f0652e
1 changed files with 16 additions and 15 deletions
|
|
@ -65,13 +65,18 @@ static void clear_item(struct spa_dict_item *item)
|
|||
free((char *) item->value);
|
||||
}
|
||||
|
||||
static int find_index(const struct pw_properties *this, const char *key)
|
||||
static struct spa_dict_item *find_item(const struct pw_properties *this, const char *key)
|
||||
{
|
||||
const struct spa_dict_item *item;
|
||||
item = spa_dict_lookup_item(&this->dict, key);
|
||||
const struct properties *impl = SPA_CONTAINER_OF(this, struct properties, this);
|
||||
const struct spa_dict_item *item = spa_dict_lookup_item(&this->dict, key);
|
||||
size_t index;
|
||||
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
return item - this->dict.items;
|
||||
return NULL;
|
||||
|
||||
index = item - this->dict.items;
|
||||
|
||||
return pw_array_get_unchecked(&impl->items, index, struct spa_dict_item);
|
||||
}
|
||||
|
||||
static struct properties *properties_new(int prealloc)
|
||||
|
|
@ -381,22 +386,19 @@ void pw_properties_free(struct pw_properties *properties)
|
|||
static int do_replace(struct pw_properties *properties, const char *key, char *value, bool copy)
|
||||
{
|
||||
struct properties *impl = SPA_CONTAINER_OF(properties, struct properties, this);
|
||||
int index;
|
||||
struct spa_dict_item *item;
|
||||
|
||||
if (key == NULL || key[0] == 0)
|
||||
goto exit_noupdate;
|
||||
|
||||
index = find_index(properties, key);
|
||||
item = find_item(properties, key);
|
||||
|
||||
if (index == -1) {
|
||||
if (item == NULL) {
|
||||
if (value == NULL)
|
||||
return 0;
|
||||
add_func(properties, strdup(key), copy ? strdup(value) : value);
|
||||
SPA_FLAG_CLEAR(properties->dict.flags, SPA_DICT_FLAG_SORTED);
|
||||
} else {
|
||||
struct spa_dict_item *item =
|
||||
pw_array_get_unchecked(&impl->items, index, struct spa_dict_item);
|
||||
|
||||
if (value && spa_streq(item->value, value))
|
||||
goto exit_noupdate;
|
||||
|
||||
|
|
@ -490,13 +492,12 @@ int pw_properties_setf(struct pw_properties *properties, const char *key, const
|
|||
SPA_EXPORT
|
||||
const char *pw_properties_get(const struct pw_properties *properties, const char *key)
|
||||
{
|
||||
struct properties *impl = SPA_CONTAINER_OF(properties, struct properties, this);
|
||||
int index = find_index(properties, key);
|
||||
struct spa_dict_item *item = find_item(properties, key);
|
||||
|
||||
if (index == -1)
|
||||
if (item == NULL)
|
||||
return NULL;
|
||||
|
||||
return pw_array_get_unchecked(&impl->items, index, struct spa_dict_item)->value;
|
||||
return item->value;
|
||||
}
|
||||
|
||||
/** Iterate property values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue