From 1f97052fe0e90781b6e4caac0ecd104bd2bf54e6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Dec 2015 19:19:56 +0100 Subject: resolved: optimize dns_cache_remove() a bit --- src/resolve/resolved-dns-cache.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/resolve') diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 65eff7fda6..2e3090b32a 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -101,18 +101,21 @@ void dns_cache_flush(DnsCache *c) { } static bool dns_cache_remove(DnsCache *c, DnsResourceKey *key) { - DnsCacheItem *i; - bool exist = false; + DnsCacheItem *first, *i, *n; assert(c); assert(key); - while ((i = hashmap_get(c->by_key, key))) { - dns_cache_item_remove_and_free(c, i); - exist = true; + first = hashmap_remove(c->by_key, key); + if (!first) + return false; + + LIST_FOREACH_SAFE(by_key, i, n, first) { + prioq_remove(c->by_expiry, i, &i->prioq_idx); + dns_cache_item_free(i); } - return exist; + return true; } static void dns_cache_make_space(DnsCache *c, unsigned add) { -- cgit v1.2.3-54-g00ecf