1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

networkd: optimize link_node_enumerator() a bit

strv_consume() is pretty expensive when invoked piecemeal, hence optimize it a bit by pre-allocating a properly sized
array.
This commit is contained in:
Lennart Poettering 2016-01-19 18:35:32 +01:00
parent 3abaabdab7
commit fdb90ac6a6

View File

@ -59,15 +59,19 @@ static char *link_bus_path(Link *link) {
int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL; _cleanup_strv_free_ char **l = NULL;
Manager *m = userdata; Manager *m = userdata;
unsigned c = 0;
Link *link; Link *link;
Iterator i; Iterator i;
int r;
assert(bus); assert(bus);
assert(path); assert(path);
assert(m); assert(m);
assert(nodes); assert(nodes);
l = new0(char*, hashmap_size(m->links) + 1);
if (!l)
return -ENOMEM;
HASHMAP_FOREACH(link, m->links, i) { HASHMAP_FOREACH(link, m->links, i) {
char *p; char *p;
@ -75,11 +79,10 @@ int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
r = strv_consume(&l, p); l[c++] = p;
if (r < 0)
return r;
} }
l[c] = NULL;
*nodes = l; *nodes = l;
l = NULL; l = NULL;