projects
/
platform
/
upstream
/
systemd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
934e749
)
hashmap: optimize set_put_strdup() a bit
author
Lennart Poettering
<lennart@poettering.net>
Fri, 29 Apr 2016 15:33:29 +0000
(17:33 +0200)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 29 Apr 2016 15:35:32 +0000
(17:35 +0200)
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.
src/basic/hashmap.c
patch
|
blob
|
history
diff --git
a/src/basic/hashmap.c
b/src/basic/hashmap.c
index
85b8d81
..
49a0479
100644
(file)
--- 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) {