git: b2dbd3d3ae33 - main - pctrie: reduce code duplication in PCTRIE_REMOVE_*
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 01 Nov 2024 16:11:35 UTC
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); \
}