Commit b02164e9 authored by Daniel Salzman's avatar Daniel Salzman

libknot: optimize code order in knot_pkt_put

parent ab3b6e9a
......@@ -543,6 +543,11 @@ int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr,
return ret;
}
/* Check for double insertion. */
if ((flags & KNOT_PF_CHECKDUP) && pkt_contains(pkt, rr)) {
return KNOT_EOK; /*! \todo return rather a number of added RRs */
}
knot_rrinfo_t *rrinfo = &pkt->rr_info[pkt->rrset_count];
memset(rrinfo, 0, sizeof(knot_rrinfo_t));
rrinfo->pos = pkt->size;
......@@ -550,14 +555,6 @@ int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr,
rrinfo->compress_ptr[0] = compr_hint;
memcpy(pkt->rr + pkt->rrset_count, rr, sizeof(knot_rrset_t));
/* Check for double insertion. */
if ((flags & KNOT_PF_CHECKDUP) && pkt_contains(pkt, rr)) {
return KNOT_EOK; /*! \todo return rather a number of added RRs */
}
uint8_t *pos = pkt->wire + pkt->size;
size_t maxlen = pkt_remaining(pkt);
/* Initialize compression context if it did not happen yet. */
pkt->compr.rrinfo = rrinfo;
if (pkt->compr.suffix.pos == 0) {
......@@ -566,6 +563,9 @@ int knot_pkt_put(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t *rr,
pkt->compr.wire);
}
uint8_t *pos = pkt->wire + pkt->size;
size_t maxlen = pkt_remaining(pkt);
/* Write RRSet to wireformat. */
ret = knot_rrset_to_wire(rr, pos, maxlen, &pkt->compr);
if (ret < 0) {
......
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