2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-15 00:34:10 +08:00

[PATCH] radix tree: code consolidation

Introduce helper any_tag_set() rather than repeat the same code sequence 4
times.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Nick Piggin 2006-01-08 01:01:40 -08:00 committed by Linus Torvalds
parent d4829cd5b4
commit 6e954b9e90

View File

@ -151,6 +151,20 @@ static inline int tag_get(struct radix_tree_node *node, int tag, int offset)
return test_bit(offset, &node->tags[tag][0]); return test_bit(offset, &node->tags[tag][0]);
} }
/*
* Returns 1 if any slot in the node has this tag set.
* Otherwise returns 0.
*/
static inline int any_tag_set(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 * Return the maximum key which can be store into a
* radix tree with height HEIGHT. * radix tree with height HEIGHT.
@ -185,15 +199,9 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
* into the newly-pushed top-level node(s) * into the newly-pushed top-level node(s)
*/ */
for (tag = 0; tag < RADIX_TREE_TAGS; tag++) { for (tag = 0; tag < RADIX_TREE_TAGS; tag++) {
int idx;
tags[tag] = 0; tags[tag] = 0;
for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) { if (any_tag_set(root->rnode, tag))
if (root->rnode->tags[tag][idx]) { tags[tag] = 1;
tags[tag] = 1;
break;
}
}
} }
do { do {
@ -427,13 +435,9 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
goto out; goto out;
do { do {
int idx;
tag_clear(pathp->node, tag, pathp->offset); tag_clear(pathp->node, tag, pathp->offset);
for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) { if (any_tag_set(pathp->node, tag))
if (pathp->node->tags[tag][idx]) goto out;
goto out;
}
pathp--; pathp--;
} while (pathp->node); } while (pathp->node);
out: out:
@ -729,19 +733,14 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
nr_cleared_tags = RADIX_TREE_TAGS; nr_cleared_tags = RADIX_TREE_TAGS;
for (tag = 0; tag < RADIX_TREE_TAGS; tag++) { for (tag = 0; tag < RADIX_TREE_TAGS; tag++) {
int idx;
if (tags[tag]) if (tags[tag])
continue; continue;
tag_clear(pathp->node, tag, pathp->offset); tag_clear(pathp->node, tag, pathp->offset);
for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) { if (any_tag_set(pathp->node, tag)) {
if (pathp->node->tags[tag][idx]) { tags[tag] = 1;
tags[tag] = 1; nr_cleared_tags--;
nr_cleared_tags--;
break;
}
} }
} }
pathp--; pathp--;
@ -770,15 +769,11 @@ EXPORT_SYMBOL(radix_tree_delete);
*/ */
int radix_tree_tagged(struct radix_tree_root *root, int tag) int radix_tree_tagged(struct radix_tree_root *root, int tag)
{ {
int idx; struct radix_tree_node *rnode;
rnode = root->rnode;
if (!root->rnode) if (!rnode)
return 0; return 0;
for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) { return any_tag_set(rnode, tag);
if (root->rnode->tags[tag][idx])
return 1;
}
return 0;
} }
EXPORT_SYMBOL(radix_tree_tagged); EXPORT_SYMBOL(radix_tree_tagged);