From 33f431fda30bc87992cf103d436d154ff8ac4167 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= <vladimir.cunat@nic.cz>
Date: Wed, 13 Jun 2018 18:04:38 +0200
Subject: [PATCH] cache: shorten repetitive `qry->flags` blocks

---
 lib/cache/entry_pkt.c | 17 +++++++++--------
 lib/cache/peek.c      | 22 +++++++++++++---------
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/lib/cache/entry_pkt.c b/lib/cache/entry_pkt.c
index bfbfce1e2..ad7bfea70 100644
--- a/lib/cache/entry_pkt.c
+++ b/lib/cache/entry_pkt.c
@@ -210,15 +210,16 @@ int answer_from_pkt(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
 	}
 
 	/* Finishing touches. TODO: perhaps factor out */
-	qry->flags.EXPIRING = is_expiring(eh->ttl, new_ttl);
-	qry->flags.CACHED = true;
-	qry->flags.NO_MINIMIZE = true;
-	qry->flags.DNSSEC_INSECURE = kr_rank_test(eh->rank, KR_RANK_INSECURE);
-	qry->flags.DNSSEC_BOGUS = kr_rank_test(eh->rank, KR_RANK_BOGUS);
-	if (qry->flags.DNSSEC_INSECURE || qry->flags.DNSSEC_BOGUS) {
-		qry->flags.DNSSEC_WANT = false;
+	struct kr_qflags * const qf = &qry->flags;
+	qf->EXPIRING = is_expiring(eh->ttl, new_ttl);
+	qf->CACHED = true;
+	qf->NO_MINIMIZE = true;
+	qf->DNSSEC_INSECURE = kr_rank_test(eh->rank, KR_RANK_INSECURE);
+	qf->DNSSEC_BOGUS = kr_rank_test(eh->rank, KR_RANK_BOGUS);
+	if (qf->DNSSEC_INSECURE || qf->DNSSEC_BOGUS) {
+		qf->DNSSEC_WANT = false;
 	}
-	qry->flags.DNSSEC_OPTOUT = eh->has_optout;
+	qf->DNSSEC_OPTOUT = eh->has_optout;
 	VERBOSE_MSG(qry, "=> satisfied by exact packet: rank 0%.2o, new TTL %d\n",
 			eh->rank, new_ttl);
 	return kr_ok();
diff --git a/lib/cache/peek.c b/lib/cache/peek.c
index 3bea5c3a9..15f757ec8 100644
--- a/lib/cache/peek.c
+++ b/lib/cache/peek.c
@@ -285,10 +285,12 @@ int peek_nosync(kr_layer_t *ctx, knot_pkt_t *pkt)
 				? "+" : "-");
 	}
 	kr_log_verbose("\n");
+
 	/* Finishing touches. */
-	qry->flags.EXPIRING = expiring;
-	qry->flags.CACHED = true;
-	qry->flags.NO_MINIMIZE = true;
+	struct kr_qflags * const qf = &qry->flags;
+	qf->EXPIRING = expiring;
+	qf->CACHED = true;
+	qf->NO_MINIMIZE = true;
 
 	return KR_STATE_DONE;
 }
@@ -409,13 +411,15 @@ static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
 	/* Put links to the materialized data into the pkt. */
 	ret = pkt_append(pkt, &ans.rrsets[AR_ANSWER], eh->rank);
 	CHECK_RET(ret);
+
 	/* Finishing touches. */
-	qry->flags.EXPIRING = is_expiring(eh->ttl, new_ttl);
-	qry->flags.CACHED = true;
-	qry->flags.NO_MINIMIZE = true;
-	qry->flags.DNSSEC_INSECURE = kr_rank_test(eh->rank, KR_RANK_INSECURE);
-	if (qry->flags.DNSSEC_INSECURE) {
-		qry->flags.DNSSEC_WANT = false;
+	struct kr_qflags * const qf = &qry->flags;
+	qf->EXPIRING = is_expiring(eh->ttl, new_ttl);
+	qf->CACHED = true;
+	qf->NO_MINIMIZE = true;
+	qf->DNSSEC_INSECURE = kr_rank_test(eh->rank, KR_RANK_INSECURE);
+	if (qf->DNSSEC_INSECURE) {
+		qf->DNSSEC_WANT = false;
 	}
 	VERBOSE_MSG(qry, "=> satisfied by exact %s: rank 0%.2o, new TTL %d\n",
 			(type == KNOT_RRTYPE_CNAME ? "CNAME" : "RRset"),
-- 
GitLab