[patch 3/5] radix tree: cleanup

From: Nick Piggin
Date: Sat Oct 29 2005 - 19:49:11 EST


3/5

--
SUSE Labs, Novell Inc.

Introduce helper tag_get_any_node rather than repeat the same code
sequence 4 times.

Signed-off-by: Nick Piggin <npiggin@xxxxxxx>

Index: linux-2.6/lib/radix-tree.c
===================================================================
--- linux-2.6.orig/lib/radix-tree.c
+++ linux-2.6/lib/radix-tree.c
@@ -150,6 +150,20 @@ static inline int tag_get(struct radix_t
}

/*
+ * Returns 1 if any slot in the node has this tag set.
+ * Otherwise returns 0.
+ */
+static inline int tag_get_any_node(struct radix_tree_node *node, int tag)
+{
+ int idx;
+ for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) {
+ if (node->tags[tag][idx])
+ return 1;
+ }
+ return 0;
+}
+
+/*
* Return the maximum key which can be store into a
* radix tree with height HEIGHT.
*/
@@ -183,15 +197,9 @@ static int radix_tree_extend(struct radi
* into the newly-pushed top-level node(s)
*/
for (tag = 0; tag < RADIX_TREE_TAGS; tag++) {
- int idx;
-
tags[tag] = 0;
- for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) {
- if (root->rnode->tags[tag][idx]) {
- tags[tag] = 1;
- break;
- }
- }
+ if (tag_get_any_node(root->rnode, tag))
+ tags[tag] = 1;
}

do {
@@ -425,13 +433,9 @@ void *radix_tree_tag_clear(struct radix_
goto out;

do {
- int idx;
-
tag_clear(pathp->node, tag, pathp->offset);
- for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) {
- if (pathp->node->tags[tag][idx])
- goto out;
- }
+ if (tag_get_any_node(pathp->node, tag))
+ goto out;
pathp--;
} while (pathp->node);
out:
@@ -727,19 +731,14 @@ void *radix_tree_delete(struct radix_tre

nr_cleared_tags = RADIX_TREE_TAGS;
for (tag = 0; tag < RADIX_TREE_TAGS; tag++) {
- int idx;
-
if (tags[tag])
continue;

tag_clear(pathp->node, tag, pathp->offset);

- for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) {
- if (pathp->node->tags[tag][idx]) {
- tags[tag] = 1;
- nr_cleared_tags--;
- break;
- }
+ if (tag_get_any_node(pathp->node, tag)) {
+ tags[tag] = 1;
+ nr_cleared_tags--;
}
}
pathp--;
@@ -768,15 +767,11 @@ EXPORT_SYMBOL(radix_tree_delete);
*/
int radix_tree_tagged(struct radix_tree_root *root, int tag)
{
- int idx;
-
- if (!root->rnode)
- return 0;
- for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) {
- if (root->rnode->tags[tag][idx])
- return 1;
- }
- return 0;
+ struct radix_tree_node *rnode;
+ rnode = root->rnode;
+ if (!rnode)
+ return 0;
+ return tag_get_any_node(rnode, tag);
}
EXPORT_SYMBOL(radix_tree_tagged);