Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Nov 2024 16:11:35 GMT
From:      Doug Moore <dougm@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b2dbd3d3ae33 - main - pctrie: reduce code duplication in PCTRIE_REMOVE_*
Message-ID:  <202411011611.4A1GBZWN080090@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by dougm:

URL: https://cgit.FreeBSD.org/src/commit/?id=b2dbd3d3ae33286baa3ce4a07bd697c50b450e7a

commit b2dbd3d3ae33286baa3ce4a07bd697c50b450e7a
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-11-01 16:10:19 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2024-11-01 16:10:19 +0000

    pctrie: reduce code duplication in PCTRIE_REMOVE_*
    
    There's a little bit of code that appears in each PCTRIE_REMOVE
    function in pctrie.h. Make a new function for it, and invoke it from
    those PCTRIE_REMOVE functions.
    
    Reviewed by:    bnovkov
    Differential Revision:  https://reviews.freebsd.org/D47320
---
 sys/sys/pctrie.h | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/sys/sys/pctrie.h b/sys/sys/pctrie.h
index 54b7fb401202..8556f08561b9 100644
--- a/sys/sys/pctrie.h
+++ b/sys/sys/pctrie.h
@@ -311,6 +311,14 @@ name##_PCTRIE_ITER_STEP_LE(struct pctrie_iter *it)			\
 }									\
 									\
 static __inline __unused void						\
+name##_PCTRIE_REMOVE_BASE(struct pctrie *ptree,				\
+    struct pctrie_node *freenode)					\
+{									\
+	if (freenode != NULL)						\
+		freefn(ptree, freenode);				\
+}									\
+									\
+static __inline __unused void						\
 name##_PCTRIE_ITER_REMOVE(struct pctrie_iter *it)			\
 {									\
 	uint64_t *val;							\
@@ -319,8 +327,7 @@ name##_PCTRIE_ITER_REMOVE(struct pctrie_iter *it)			\
 	val = pctrie_iter_remove(it, &freenode);			\
 	if (val == NULL)						\
 		panic("%s: key not found", __func__);			\
-	if (freenode != NULL)						\
-		freefn(it->ptree, freenode);				\
+	name##_PCTRIE_REMOVE_BASE(it->ptree, freenode);			\
 }									\
 									\
 static __inline __unused struct type *					\
@@ -340,8 +347,7 @@ name##_PCTRIE_REMOVE(struct pctrie *ptree, uint64_t key)		\
 	val = pctrie_remove_lookup(ptree, key, &freenode);		\
 	if (val == NULL)						\
 		panic("%s: key not found", __func__);			\
-	if (freenode != NULL)						\
-		freefn(ptree, freenode);				\
+	name##_PCTRIE_REMOVE_BASE(ptree, freenode);			\
 }									\
 									\
 static __inline __unused struct type *					\
@@ -351,8 +357,7 @@ name##_PCTRIE_REMOVE_LOOKUP(struct pctrie *ptree, uint64_t key)		\
 	struct pctrie_node *freenode;					\
 									\
 	val = pctrie_remove_lookup(ptree, key, &freenode);		\
-	if (freenode != NULL)						\
-		freefn(ptree, freenode);				\
+	name##_PCTRIE_REMOVE_BASE(ptree, freenode);			\
 	return name##_PCTRIE_VAL2PTR(val);				\
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202411011611.4A1GBZWN080090>