Commit dacc510f authored by Marek Vavruša's avatar Marek Vavruša

lib: faster rdata iterators

parent 2384504f
......@@ -27,6 +27,7 @@
#include "lib/cache.h"
#include "lib/defines.h"
#include "lib/utils.h"
/* Key size */
#define KEY_HSIZE (1 + sizeof(uint16_t))
......@@ -274,20 +275,22 @@ int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t dr
return kr_error(ENOMEM);
}
knot_rdata_t *rd = knot_rdataset_at(&src->rrs, 0);
knot_rdata_t *rd_dst = NULL;
/* Copy valid records */
knot_rdata_t *rd = src->rrs.data;
for (uint16_t i = 0; i < src->rrs.rr_count; ++i) {
if (knot_rdata_ttl(rd) >= drift) {
/* Append record */
if (knot_rdataset_add(&dst->rrs, rd, mm) != 0) {
knot_rrset_clear(dst, mm);
return kr_error(ENOMEM);
}
/* Fixup TTL time drift */
rd_dst = knot_rdataset_at(&dst->rrs, dst->rrs.rr_count - 1);
knot_rdata_set_ttl(rd_dst, knot_rdata_ttl(rd) - drift);
}
rd += knot_rdata_array_size(knot_rdata_rdlen(rd));
rd = kr_rdataset_next(rd);
}
/* Fixup TTL by time passed */
rd = dst->rrs.data;
for (uint16_t i = 0; i < dst->rrs.rr_count; ++i) {
knot_rdata_set_ttl(rd, knot_rdata_ttl(rd) - drift);
rd = kr_rdataset_next(rd);
}
return kr_ok();
......@@ -310,11 +313,12 @@ int kr_cache_insert_rr(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint32_
.ttl = 0,
.count = rr->rrs.rr_count
};
knot_rdata_t *rd = rr->rrs.data;
for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) {
knot_rdata_t *rd = knot_rdataset_at(&rr->rrs, i);
if (knot_rdata_ttl(rd) > header.ttl) {
header.ttl = knot_rdata_ttl(rd);
}
rd = kr_rdataset_next(rd);
}
namedb_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) };
......
......@@ -150,7 +150,7 @@ static void follow_cname_chain(const knot_dname_t **cname, const knot_rrset_t *r
static int update_nsaddr(const knot_rrset_t *rr, struct kr_query *query)
{
if (rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA) {
const knot_rdata_t *rdata = knot_rdataset_at(&rr->rrs, 0);
const knot_rdata_t *rdata = rr->rrs.data;
int ret = kr_zonecut_add(&query->zone_cut, rr->owner, rdata);
if (ret != 0) {
return KNOT_STATE_FAIL;
......
......@@ -45,13 +45,13 @@ static uint32_t limit_ttl(uint32_t ttl)
static void adjust_ttl(knot_rrset_t *rr, uint32_t drift)
{
knot_rdata_t *rd = knot_rdataset_at(&rr->rrs, 0);
knot_rdata_t *rd = rr->rrs.data;
for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) {
uint32_t ttl = knot_rdata_ttl(rd);
if (ttl >= drift) {
knot_rdata_set_ttl(rd, ttl - drift);
}
rd += knot_rdata_array_size(knot_rdata_rdlen(rd));
rd = kr_rdataset_next(rd);
}
}
......@@ -148,13 +148,13 @@ static uint32_t packet_ttl(knot_pkt_t *pkt)
if (rr->type == KNOT_RRTYPE_OPT || rr->type == KNOT_RRTYPE_TSIG) {
continue;
}
knot_rdata_t *rd = knot_rdataset_at(&rr->rrs, 0);
knot_rdata_t *rd = rr->rrs.data;
for (uint16_t j = 0; j < rr->rrs.rr_count; ++j) {
if (knot_rdata_ttl(rd) < ttl) {
ttl = knot_rdata_ttl(rd);
has_ttl = true;
}
rd += knot_rdata_array_size(knot_rdata_rdlen(rd));
rd = kr_rdataset_next(rd);
}
}
}
......
......@@ -44,6 +44,9 @@ extern void _cleanup_fclose(FILE **p);
knot_pkt_parse_question((pkt)); \
} while (0)
/** @internal Next RDATA shortcut. */
#define kr_rdataset_next(rd) (rd + knot_rdata_array_size(knot_rdata_rdlen(rd)))
/** Concatenate N strings. */
char* kr_strcatdup(unsigned n, ...);
......
......@@ -275,12 +275,12 @@ static void fetch_addr(struct kr_zonecut *cut, const knot_dname_t *ns, uint16_t
return;
}
knot_rdata_t *rd = knot_rdataset_at(&cached_rr.rrs, 0);
knot_rdata_t *rd = cached_rr.rrs.data;
for (uint16_t i = 0; i < cached_rr.rrs.rr_count; ++i) {
if (knot_rdata_ttl(rd) > timestamp) {
(void) kr_zonecut_add(cut, ns, rd);
}
rd += knot_rdata_array_size(knot_rdata_rdlen(rd));
rd = kr_rdataset_next(rd);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment