From dfeb726476193fee3add70d91c665e0a1be83289 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 3 Jan 2016 17:00:40 +0000 Subject: [PATCH] Constify radix tree search code --- src/libutil/radix.c | 15 ++++++++------- src/libutil/radix.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libutil/radix.c b/src/libutil/radix.c index a6a49025a..11acc4f8a 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -70,10 +70,10 @@ struct radix_tree_compressed { static gboolean radix_compare_compressed (struct radix_compressed_node *node, - guint8 *key, guint keylen, guint cur_level) + const guint8 *key, guint keylen, guint cur_level) { - guint8 *nk; - guint8 *k; + const guint8 *nk; + const guint8 *k; guint8 bit; guint shift, rbits, skip; @@ -118,13 +118,13 @@ radix_compare_compressed (struct radix_compressed_node *node, } uintptr_t -radix_find_compressed (radix_compressed_t * tree, guint8 *key, gsize keylen) +radix_find_compressed (radix_compressed_t * tree, const guint8 *key, gsize keylen) { struct radix_compressed_node *node; guint32 bit; gsize kremain = keylen / sizeof (guint32); uintptr_t value; - guint32 *k = (guint32 *)key; + const guint32 *k = (guint32 *)key; guint32 kv = ntohl (*k); guint cur_level = 0; @@ -594,9 +594,10 @@ radix_destroy_compressed (radix_compressed_t *tree) } uintptr_t -radix_find_compressed_addr (radix_compressed_t *tree, rspamd_inet_addr_t *addr) +radix_find_compressed_addr (radix_compressed_t *tree, + const rspamd_inet_addr_t *addr) { - guchar *key; + const guchar *key; guint klen = 0; if (addr == NULL) { diff --git a/src/libutil/radix.h b/src/libutil/radix.h index 4200cf65e..cd27084a1 100644 --- a/src/libutil/radix.h +++ b/src/libutil/radix.h @@ -56,7 +56,7 @@ radix_insert_compressed (radix_compressed_t * tree, * @param keylen length of a key * @return opaque pointer or `RADIX_NO_VALUE` if no value has been found */ -uintptr_t radix_find_compressed (radix_compressed_t * tree, guint8 *key, +uintptr_t radix_find_compressed (radix_compressed_t * tree, const guint8 *key, gsize keylen); /** @@ -66,7 +66,7 @@ uintptr_t radix_find_compressed (radix_compressed_t * tree, guint8 *key, * @return */ uintptr_t radix_find_compressed_addr (radix_compressed_t *tree, - rspamd_inet_addr_t *addr); + const rspamd_inet_addr_t *addr); /** * Destroy the complete radix trie -- 2.39.5