Merge pull request #11776 from keszybz/networkd-ordered-sets
Store domains lists in OrderedSets in networkd
This commit is contained in:
+1
-4
@@ -1536,7 +1536,6 @@ void *internal_hashmap_first_key_and_value(HashmapBase *h, bool remove, void **r
|
||||
}
|
||||
|
||||
unsigned internal_hashmap_size(HashmapBase *h) {
|
||||
|
||||
if (!h)
|
||||
return 0;
|
||||
|
||||
@@ -1544,7 +1543,6 @@ unsigned internal_hashmap_size(HashmapBase *h) {
|
||||
}
|
||||
|
||||
unsigned internal_hashmap_buckets(HashmapBase *h) {
|
||||
|
||||
if (!h)
|
||||
return 0;
|
||||
|
||||
@@ -1904,8 +1902,7 @@ IteratedCache *iterated_cache_free(IteratedCache *cache) {
|
||||
if (cache) {
|
||||
free(cache->keys.ptr);
|
||||
free(cache->values.ptr);
|
||||
free(cache);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return mfree(cache);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "fileio.h"
|
||||
#include "ordered-set.h"
|
||||
#include "strv.h"
|
||||
|
||||
@@ -45,3 +46,37 @@ int ordered_set_put_strdupv(OrderedSet *s, char **l) {
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l) {
|
||||
int n = 0, r;
|
||||
Iterator i;
|
||||
char *p;
|
||||
|
||||
/* Like ordered_set_put_strv, but for an OrderedSet of strings */
|
||||
|
||||
ORDERED_SET_FOREACH(p, l, i) {
|
||||
r = ordered_set_put_strdup(s, p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
n += r;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void ordered_set_print(FILE *f, const char *field, OrderedSet *s) {
|
||||
bool space = false;
|
||||
Iterator i;
|
||||
char *p;
|
||||
|
||||
if (ordered_set_isempty(s))
|
||||
return;
|
||||
|
||||
fputs(field, f);
|
||||
|
||||
ORDERED_SET_FOREACH(p, s, i)
|
||||
fputs_with_space(f, p, NULL, &space);
|
||||
|
||||
fputc('\n', f);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "hashmap.h"
|
||||
|
||||
typedef struct OrderedSet OrderedSet;
|
||||
@@ -48,9 +50,15 @@ static inline void* ordered_set_steal_first(OrderedSet *s) {
|
||||
return ordered_hashmap_steal_first((OrderedHashmap*) s);
|
||||
}
|
||||
|
||||
static inline char **ordered_set_get_strv(OrderedSet *s) {
|
||||
return internal_hashmap_get_strv(HASHMAP_BASE((OrderedHashmap*) s));
|
||||
}
|
||||
|
||||
int ordered_set_consume(OrderedSet *s, void *p);
|
||||
int ordered_set_put_strdup(OrderedSet *s, const char *p);
|
||||
int ordered_set_put_strdupv(OrderedSet *s, char **l);
|
||||
int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l);
|
||||
void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
|
||||
|
||||
#define ORDERED_SET_FOREACH(e, s, i) \
|
||||
for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); )
|
||||
|
||||
Reference in New Issue
Block a user