summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-29 17:33:29 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-29 17:35:32 +0200
commit454f0f8680ebbded135e8575b4d9615b427fdf76 (patch)
tree1001934d129716b22fbab80554ce7da2df4a8929 /src/basic
parent934e749e18bc0641a3dc8d83c4f16a2ba4c8d966 (diff)
hashmap: optimize set_put_strdup() a bit
Hashing should be quicker than allocating, hence let's first check if the string already exists and only then allocate a new copy for it.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/hashmap.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 85b8d812b3..49a0479592 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -1773,20 +1773,18 @@ int set_consume(Set *s, void *value) {
int set_put_strdup(Set *s, const char *p) {
char *c;
- int r;
assert(s);
assert(p);
+ if (set_contains(s, (char*) p))
+ return 0;
+
c = strdup(p);
if (!c)
return -ENOMEM;
- r = set_consume(s, c);
- if (r == -EEXIST)
- return 0;
-
- return r;
+ return set_consume(s, c);
}
int set_put_strdupv(Set *s, char **l) {