Commit b17c14b2 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Make simple getter/setter-like functions static inline

parent 14e6b11b
Pipeline #32605 passed with stages
in 12 minutes and 42 seconds
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -285,16 +285,6 @@ bool node_rrtype_is_signed(const zone_node_t *node, uint16_t type)
return false;
}
bool node_rrtype_exists(const zone_node_t *node, uint16_t type)
{
return node_rdataset(node, type) != NULL;
}
bool node_empty(const zone_node_t *node)
{
return node == NULL || node->rrset_count == 0;
}
bool node_bitmap_equal(const zone_node_t *a, const zone_node_t *b)
{
if (a == NULL || b == NULL || a->rrset_count != b->rrset_count) {
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -197,7 +197,10 @@ bool node_rrtype_is_signed(const zone_node_t *node, uint16_t type);
*
* \return True/False.
*/
bool node_rrtype_exists(const zone_node_t *node, uint16_t type);
inline static bool node_rrtype_exists(const zone_node_t *node, uint16_t type)
{
return node_rdataset(node, type) != NULL;
}
/*!
* \brief Checks whether node is empty. Node is empty when NULL or when no
......@@ -207,7 +210,10 @@ bool node_rrtype_exists(const zone_node_t *node, uint16_t type);
*
* \return True/False.
*/
bool node_empty(const zone_node_t *node);
inline static bool node_empty(const zone_node_t *node)
{
return node == NULL || node->rrset_count == 0;
}
/*!
* \brief Check whether two nodes have equal set of rrtypes.
......
......@@ -27,20 +27,6 @@ zone_tree_t *zone_tree_create(void)
return trie_create(NULL);
}
size_t zone_tree_count(const zone_tree_t *tree)
{
if (tree == NULL) {
return 0;
}
return trie_weight(tree);
}
bool zone_tree_is_empty(const zone_tree_t *tree)
{
return zone_tree_count(tree) == 0;
}
int zone_tree_insert(zone_tree_t *tree, zone_node_t *node)
{
if (tree == NULL || node == NULL) {
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -40,7 +40,14 @@ zone_tree_t *zone_tree_create(void);
*
* \return number of nodes in tree.
*/
size_t zone_tree_count(const zone_tree_t *tree);
inline static size_t zone_tree_count(const zone_tree_t *tree)
{
if (tree == NULL) {
return 0;
}
return trie_weight(tree);
}
/*!
* \brief Checks if the zone tree is empty.
......@@ -49,7 +56,10 @@ size_t zone_tree_count(const zone_tree_t *tree);
*
* \return Nonzero if the zone tree is empty.
*/
bool zone_tree_is_empty(const zone_tree_t *tree);
inline static bool zone_tree_is_empty(const zone_tree_t *tree)
{
return zone_tree_count(tree) == 0;
}
/*!
* \brief Inserts the given node into the zone tree.
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -135,17 +135,6 @@ static int remove_rr_at(knot_rdataset_t *rrs, uint16_t pos, knot_mm_t *mm)
return KNOT_EOK;
}
_public_
void knot_rdataset_init(knot_rdataset_t *rrs)
{
if (rrs == NULL) {
return;
}
rrs->rr_count = 0;
rrs->data = NULL;
}
_public_
void knot_rdataset_clear(knot_rdataset_t *rrs, knot_mm_t *mm)
{
......
......@@ -43,7 +43,13 @@ typedef struct {
*
* \param rrs Structure to be initialized.
*/
void knot_rdataset_init(knot_rdataset_t *rrs);
inline static void knot_rdataset_init(knot_rdataset_t *rrs)
{
if (rrs != NULL) {
rrs->rr_count = 0;
rrs->data = NULL;
}
}
/*!
* \brief Frees data initialized by RRS structure, but not the structure itself.
......
......@@ -19,9 +19,6 @@
#include <stdint.h>
#include "libknot/attribute.h"
#include "libknot/consts.h"
#include "libknot/descriptor.h"
#include "libknot/dname.h"
#include "libknot/errcode.h"
#include "libknot/rrset.h"
#include "libknot/rrtype/naptr.h"
......@@ -48,24 +45,6 @@ knot_rrset_t *knot_rrset_new(const knot_dname_t *owner, uint16_t type,
return ret;
}
_public_
void knot_rrset_init(knot_rrset_t *rrset, knot_dname_t *owner, uint16_t type,
uint16_t rclass, uint32_t ttl)
{
rrset->owner = owner;
rrset->type = type;
rrset->rclass = rclass;
rrset->ttl = ttl;
knot_rdataset_init(&rrset->rrs);
rrset->additional = NULL;
}
_public_
void knot_rrset_init_empty(knot_rrset_t *rrset)
{
knot_rrset_init(rrset, NULL, 0, KNOT_CLASS_IN, 0);
}
_public_
knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, knot_mm_t *mm)
{
......@@ -104,10 +83,12 @@ void knot_rrset_free(knot_rrset_t **rrset, knot_mm_t *mm)
_public_
void knot_rrset_clear(knot_rrset_t *rrset, knot_mm_t *mm)
{
if (rrset) {
knot_rdataset_clear(&rrset->rrs, mm);
knot_dname_free(&rrset->owner, mm);
if (rrset == NULL) {
return;
}
knot_rdataset_clear(&rrset->rrs, mm);
knot_dname_free(&rrset->owner, mm);
}
_public_
......@@ -153,17 +134,6 @@ bool knot_rrset_equal(const knot_rrset_t *r1,
return true;
}
_public_
bool knot_rrset_empty(const knot_rrset_t *rrset)
{
if (rrset) {
uint16_t rr_count = rrset->rrs.rr_count;
return rr_count == 0;
} else {
return true;
}
}
_public_
bool knot_rrset_is_nsec3rel(const knot_rrset_t *rr)
{
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -28,6 +28,7 @@
#include <stdbool.h>
#include "libknot/dname.h"
#include "libknot/descriptor.h"
#include "libknot/mm_ctx.h"
#include "libknot/rdataset.h"
......@@ -36,7 +37,7 @@
*
* For RRSet definition see RFC2181, Section 5.
*/
struct knot_rrset {
typedef struct {
knot_dname_t *owner; /*!< Domain name being the owner of the RRSet. */
uint32_t ttl; /*!< TTL of the RRset. */
uint16_t type; /*!< TYPE of the RRset. */
......@@ -44,9 +45,7 @@ struct knot_rrset {
knot_rdataset_t rrs; /*!< RRSet's RRs */
/* Optional fields. */
void *additional; /*!< Additional records. */
};
typedef struct knot_rrset knot_rrset_t;
} knot_rrset_t;
/*! \todo Documentation */
typedef enum {
......@@ -55,8 +54,6 @@ typedef enum {
KNOT_RRSET_COMPARE_WHOLE
} knot_rrset_compare_type_t;
/* -------------------- Creation / initialization --------------------------- */
/*!
* \brief Creates a new RRSet with the given properties.
*
......@@ -82,15 +79,28 @@ knot_rrset_t *knot_rrset_new(const knot_dname_t *owner, uint16_t type,
* \param rclass Class to use.
* \param ttl TTL to use.
*/
void knot_rrset_init(knot_rrset_t *rrset, knot_dname_t *owner, uint16_t type,
uint16_t rclass, uint32_t ttl);
inline static void knot_rrset_init(knot_rrset_t *rrset, knot_dname_t *owner,
uint16_t type, uint16_t rclass, uint32_t ttl)
{
if (rrset != NULL) {
rrset->owner = owner;
rrset->type = type;
rrset->rclass = rclass;
rrset->ttl = ttl;
knot_rdataset_init(&rrset->rrs);
rrset->additional = NULL;
}
}
/*!
* \brief Initializes given RRSet structure.
*
* \param rrset RRSet to init.
*/
void knot_rrset_init_empty(knot_rrset_t *rrset);
inline static void knot_rrset_init_empty(knot_rrset_t *rrset)
{
knot_rrset_init(rrset, NULL, 0, KNOT_CLASS_IN, 0);
}
/*!
* \brief Creates new RRSet from \a src RRSet.
......@@ -103,8 +113,6 @@ void knot_rrset_init_empty(knot_rrset_t *rrset);
*/
knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, knot_mm_t *mm);
/* ---------------------------- Cleanup ------------------------------------- */
/*!
* \brief Destroys the RRSet structure and all its substructures.
)
......@@ -123,8 +131,6 @@ void knot_rrset_free(knot_rrset_t **rrset, knot_mm_t *mm);
*/
void knot_rrset_clear(knot_rrset_t *rrset, knot_mm_t *mm);
/* ---------- RR addition. (legacy, functionality in knot_rdataset_t) ------- */
/*!
* \brief Adds the given RDATA to the RRSet.
*
......@@ -138,8 +144,6 @@ void knot_rrset_clear(knot_rrset_t *rrset, knot_mm_t *mm);
int knot_rrset_add_rdata(knot_rrset_t *rrset, const uint8_t *data, uint16_t len,
knot_mm_t *mm);
/* ------------------ Equality / emptines bool checks ----------------------- */
/*!
* \brief Compares two RRSets for equality.
*
......@@ -161,9 +165,10 @@ bool knot_rrset_equal(const knot_rrset_t *r1, const knot_rrset_t *r2,
* \retval True if RRSet is empty.
* \retval False if RRSet is not empty.
*/
bool knot_rrset_empty(const knot_rrset_t *rrset);
/* --------------------------- Miscellaneous --------------------------------- */
inline static bool knot_rrset_empty(const knot_rrset_t *rrset)
{
return rrset == NULL || rrset->rrs.rr_count == 0;
}
/*!
* \brief Return whether the RR type is NSEC3 related (NSEC3 or RRSIG).
......
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