Page MenuHomeFreeBSD

D47288.diff
No OneTemporary

D47288.diff

diff --git a/sys/sys/pctrie.h b/sys/sys/pctrie.h
--- a/sys/sys/pctrie.h
+++ b/sys/sys/pctrie.h
@@ -86,69 +86,67 @@
} \
\
static __inline __unused int \
-name##_PCTRIE_INSERT(struct pctrie *ptree, struct type *ptr) \
+name##_PCTRIE_INSERT_BASE(struct pctrie *ptree, void *parentp, \
+ uint64_t *val, uint64_t *found, struct type **found_out) \
{ \
struct pctrie_node *parent; \
+ \
+ if (__predict_false(found != NULL)) { \
+ *found_out = name##_PCTRIE_VAL2PTR(found); \
+ return (EEXIST); \
+ } \
+ if (parentp != NULL) { \
+ parent = allocfn(ptree); \
+ if (__predict_false(parent == NULL)) { \
+ if (found_out != NULL) \
+ *found_out = NULL; \
+ return (ENOMEM); \
+ } \
+ pctrie_insert_node(parentp, parent, val); \
+ } \
+ return (0); \
+} \
+ \
+static __inline __unused int \
+name##_PCTRIE_INSERT(struct pctrie *ptree, struct type *ptr) \
+{ \
void *parentp; \
uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \
\
parentp = pctrie_insert_lookup_strict(ptree, val); \
- if (parentp == NULL) \
- return (0); \
- parent = allocfn(ptree); \
- if (__predict_false(parent == NULL)) \
- return (ENOMEM); \
- pctrie_insert_node(parentp, parent, val); \
- return (0); \
+ return (name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \
+ NULL, NULL)); \
} \
\
static __inline __unused int \
name##_PCTRIE_FIND_OR_INSERT(struct pctrie *ptree, struct type *ptr, \
struct type **found_out_opt) \
{ \
- struct pctrie_node *parent; \
void *parentp; \
uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \
uint64_t *found; \
\
parentp = pctrie_insert_lookup(ptree, val, &found); \
- if (found != NULL) { \
- if (found_out_opt != NULL) \
- *found_out_opt = name##_PCTRIE_VAL2PTR(found); \
- return (EEXIST); \
- } \
- if (parentp == NULL) \
- return (0); \
- parent = allocfn(ptree); \
- if (__predict_false(parent == NULL)) \
- return (ENOMEM); \
- pctrie_insert_node(parentp, parent, val); \
- return (0); \
+ return (name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \
+ found, found_out_opt)); \
} \
\
static __inline __unused int \
name##_PCTRIE_INSERT_LOOKUP_GE(struct pctrie *ptree, struct type *ptr, \
struct type **found_out) \
{ \
- struct pctrie_node *parent, *neighbor; \
+ struct pctrie_node *neighbor; \
void *parentp; \
uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \
uint64_t *found; \
+ int retval; \
\
parentp = pctrie_insert_lookup_gt(ptree, val, &found, \
&neighbor); \
- if (__predict_false(found != NULL)) { \
- *found_out = name##_PCTRIE_VAL2PTR(found); \
- return (EEXIST); \
- } \
- if (parentp != NULL) { \
- parent = allocfn(ptree); \
- if (__predict_false(parent == NULL)) { \
- *found_out = NULL; \
- return (ENOMEM); \
- } \
- pctrie_insert_node(parentp, parent, val); \
- } \
+ retval = name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \
+ found, found_out); \
+ if (retval != 0) \
+ return (retval); \
found = pctrie_subtree_lookup_gt(neighbor, *val); \
*found_out = name##_PCTRIE_VAL2PTR(found); \
pctrie_subtree_lookup_gt_assert(neighbor, *val, ptree, found); \
@@ -159,25 +157,18 @@
name##_PCTRIE_INSERT_LOOKUP_LE(struct pctrie *ptree, struct type *ptr, \
struct type **found_out) \
{ \
- struct pctrie_node *parent, *neighbor; \
+ struct pctrie_node *neighbor; \
void *parentp; \
uint64_t *val = name##_PCTRIE_PTR2VAL(ptr); \
uint64_t *found; \
+ int retval; \
\
parentp = pctrie_insert_lookup_lt(ptree, val, &found, \
&neighbor); \
- if (__predict_false(found != NULL)) { \
- *found_out = name##_PCTRIE_VAL2PTR(found); \
- return (EEXIST); \
- } \
- if (parentp != NULL) { \
- parent = allocfn(ptree); \
- if (__predict_false(parent == NULL)) { \
- *found_out = NULL; \
- return (ENOMEM); \
- } \
- pctrie_insert_node(parentp, parent, val); \
- } \
+ retval = name##_PCTRIE_INSERT_BASE(ptree, parentp, val, \
+ found, found_out); \
+ if (retval != 0) \
+ return (retval); \
found = pctrie_subtree_lookup_lt(neighbor, *val); \
*found_out = name##_PCTRIE_VAL2PTR(found); \
pctrie_subtree_lookup_lt_assert(neighbor, *val, ptree, found); \

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 31, 11:23 PM (2 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28215055
Default Alt Text
D47288.diff (4 KB)

Event Timeline