summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-12-18 19:25:04 +0100
committerLennart Poettering <lennart@poettering.net>2015-12-18 19:25:04 +0100
commitef9a3e3c28095e52f8ffe96acf3c70b2babfacb5 (patch)
treed61841811ee64d5d00f6361f6a9887a82f92eda6 /src
parentf5bdeb01e4c9f479aaa31cebfa6cfa85ae8a7336 (diff)
resolve: optimize dns_cache_flush() a bit
Let's use dns_cache_remove() rather than dns_cache_item_remove_and_free() to destroy the cache, since the former requires far fewer hash table lookups.
Diffstat (limited to 'src')
-rw-r--r--src/resolve/resolved-dns-cache.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index e8e349748a..a4fc185514 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -85,21 +85,6 @@ static void dns_cache_item_remove_and_free(DnsCache *c, DnsCacheItem *i) {
dns_cache_item_free(i);
}
-void dns_cache_flush(DnsCache *c) {
- DnsCacheItem *i;
-
- assert(c);
-
- while ((i = hashmap_first(c->by_key)))
- dns_cache_item_remove_and_free(c, i);
-
- assert(hashmap_size(c->by_key) == 0);
- assert(prioq_size(c->by_expiry) == 0);
-
- c->by_key = hashmap_free(c->by_key);
- c->by_expiry = prioq_free(c->by_expiry);
-}
-
static bool dns_cache_remove_by_rr(DnsCache *c, DnsResourceRecord *rr) {
DnsCacheItem *first, *i;
int r;
@@ -136,6 +121,21 @@ static bool dns_cache_remove(DnsCache *c, DnsResourceKey *key) {
return true;
}
+void dns_cache_flush(DnsCache *c) {
+ DnsResourceKey *key;
+
+ assert(c);
+
+ while ((key = hashmap_first_key(c->by_key)))
+ dns_cache_remove(c, key);
+
+ assert(hashmap_size(c->by_key) == 0);
+ assert(prioq_size(c->by_expiry) == 0);
+
+ c->by_key = hashmap_free(c->by_key);
+ c->by_expiry = prioq_free(c->by_expiry);
+}
+
static void dns_cache_make_space(DnsCache *c, unsigned add) {
assert(c);