set: introduce set_to_strv()
It is similar to set_get_strv(), but invalidates the set on success.
This commit is contained in:
@@ -1805,6 +1805,23 @@ char** _hashmap_get_strv(HashmapBase *h) {
|
||||
return sv;
|
||||
}
|
||||
|
||||
char** set_to_strv(Set **s) {
|
||||
assert(s);
|
||||
|
||||
/* This is similar to set_get_strv(), but invalidates the set on success. */
|
||||
|
||||
char **v = new(char*, set_size(*s) + 1);
|
||||
if (!v)
|
||||
return NULL;
|
||||
|
||||
for (char **p = v; (*p = set_steal_first(*s)); p++)
|
||||
;
|
||||
|
||||
assert(set_isempty(*s));
|
||||
*s = set_free(*s);
|
||||
return v;
|
||||
}
|
||||
|
||||
void* ordered_hashmap_next(OrderedHashmap *h, const void *key) {
|
||||
struct ordered_hashmap_entry *e;
|
||||
unsigned hash, idx;
|
||||
|
||||
@@ -114,6 +114,8 @@ static inline char **set_get_strv(Set *s) {
|
||||
return _hashmap_get_strv(HASHMAP_BASE(s));
|
||||
}
|
||||
|
||||
char** set_to_strv(Set **s);
|
||||
|
||||
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS);
|
||||
#define set_ensure_put(s, hash_ops, key) _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user