Skip to content

Commit 1981128

Browse files
RichardWeiYangakpm00
authored andcommitted
lib/interval_tree: skip the check before go to the right subtree
The interval_tree_subtree_search() holds the loop invariant: start <= node->ITSUBTREE Let's say we have a following tree: node / \ left right So we know node->ITSUBTREE is contributed by one of the following: * left->ITSUBTREE * ITLAST(node) * right->ITSUBTREE When we come to the right node, we are sure the first two don't contribute to node->ITSUBTREE and it must be the right node does the job. So skip the check before go to the right subtree. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Wei Yang <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michel Lespinasse <[email protected]> Cc: Jason Gunthorpe <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ccaf3ef commit 1981128

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

include/linux/interval_tree_generic.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,8 @@ ITPREFIX ## _subtree_search(ITSTRUCT *node, ITTYPE start, ITTYPE last) \
104104
if (ITSTART(node) <= last) { /* Cond1 */ \
105105
if (start <= ITLAST(node)) /* Cond2 */ \
106106
return node; /* node is leftmost match */ \
107-
if (node->ITRB.rb_right) { \
108-
node = rb_entry(node->ITRB.rb_right, \
109-
ITSTRUCT, ITRB); \
110-
if (start <= node->ITSUBTREE) \
111-
continue; \
112-
} \
107+
node = rb_entry(node->ITRB.rb_right, ITSTRUCT, ITRB); \
108+
continue; \
113109
} \
114110
return NULL; /* No match */ \
115111
} \

0 commit comments

Comments
 (0)