mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
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.
This commit is contained in:
parent
934e749e18
commit
454f0f8680
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user