[PATCH 2/2] rbtree: Rename find header in find control
Sebastian Huber
sebastian.huber at embedded-brains.de
Sat Jul 26 10:54:51 UTC 2014
Simplify _RBTree_Find_control(). Avoid superfluous NULL pointer checks.
---
cpukit/sapi/include/rtems/rbtree.h | 8 ++++----
cpukit/score/include/rtems/score/rbtree.h | 29 ++++++++++++++++++----------
testsuites/sptests/sprbtree01/init.c | 9 ++-------
testsuites/sptests/sprbtree01/sprbtree01.scn | 2 +-
4 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/cpukit/sapi/include/rtems/rbtree.h b/cpukit/sapi/include/rtems/rbtree.h
index dbc6d20..4e6d852 100644
--- a/cpukit/sapi/include/rtems/rbtree.h
+++ b/cpukit/sapi/include/rtems/rbtree.h
@@ -369,13 +369,13 @@ RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_max(
}
/**
- * @copydoc _RBTree_Find_header()
+ * @copydoc _RBTree_Find_control()
*/
-RTEMS_INLINE_ROUTINE rtems_rbtree_control *rtems_rbtree_find_header(
- rtems_rbtree_node *the_node
+RTEMS_INLINE_ROUTINE rtems_rbtree_control *rtems_rbtree_find_control(
+ const rtems_rbtree_node *the_node
)
{
- return _RBTree_Find_header( the_node );
+ return _RBTree_Find_control( the_node );
}
/**
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index 94c8ee5..c4effce 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -431,19 +431,28 @@ RTEMS_INLINE_ROUTINE bool _RBTree_Is_root(
}
/**
- * @brief Find the RBTree_Control header given a node in the tree.
+ * @brief Finds the red-black tree control given a node in the tree.
*
- * This function returns a pointer to the header of the Red Black
- * Tree containing @a the_node if it exists, and NULL if not.
+ * In case the node is not a node of a tree, then this function yields
+ * unpredictable results.
+ *
+ * @param[in] the_node The node of interest.
+ *
+ * @return The red-black tree control of the node.
*/
-RTEMS_INLINE_ROUTINE RBTree_Control *_RBTree_Find_header(
- RBTree_Node *the_node
- )
+RTEMS_INLINE_ROUTINE RBTree_Control *_RBTree_Find_control(
+ const RBTree_Node *the_node
+)
{
- if(!the_node) return NULL;
- if(!(the_node->parent)) return NULL;
- while(the_node->parent) the_node = the_node->parent;
- return (RBTree_Control*)the_node;
+ RBTree_Node *parent = the_node->parent;
+ RBTree_Control *rbtree;
+
+ do {
+ rbtree = (RBTree_Control *) parent;
+ parent = parent->parent;
+ } while ( parent != NULL );
+
+ return rbtree;
}
/**
diff --git a/testsuites/sptests/sprbtree01/init.c b/testsuites/sptests/sprbtree01/init.c
index 68b2c92..c43871a 100644
--- a/testsuites/sptests/sprbtree01/init.c
+++ b/testsuites/sptests/sprbtree01/init.c
@@ -580,8 +580,8 @@ rtems_task Init( rtems_task_argument ignored )
}
p = rb_find_unique(&rbtree1, &search_node.Node);
- puts( "INIT - Verify rtems_rbtree_find_header" );
- if (rtems_rbtree_find_header(p) != &rbtree1) {
+ puts( "INIT - Verify rtems_rbtree_find_control" );
+ if (rtems_rbtree_find_control(p) != &rbtree1) {
puts ("INIT - ERROR ON RBTREE HEADER MISMATCH");
rtems_test_exit(0);
}
@@ -620,11 +620,6 @@ rtems_task Init( rtems_task_argument ignored )
rtems_test_exit(0);
}
- if (rtems_rbtree_find_header(NULL) != NULL) {
- puts ("INIT - ERROR ON RBTREE HEADER MISMATCH");
- rtems_test_exit(0);
- }
-
puts("INIT - Insert 20 random numbers");
for (i = 0; i < 20; i++) {
node_array[i].id = numbers[i];
diff --git a/testsuites/sptests/sprbtree01/sprbtree01.scn b/testsuites/sptests/sprbtree01/sprbtree01.scn
index 0d37566..73491be 100644
--- a/testsuites/sptests/sprbtree01/sprbtree01.scn
+++ b/testsuites/sptests/sprbtree01/sprbtree01.scn
@@ -18,7 +18,7 @@ INIT - Removing 100 nodes
INIT - Verify rtems_rbtree_get_max with 100 nodes value [0,99]
INIT - Verify rtems_rbtree_find
INIT - Verify rtems_rbtree_predecessor/successor
-INIT - Verify rtems_rbtree_find_header
+INIT - Verify rtems_rbtree_find_control
INIT - Removing 100 nodes
INIT - Insert 20 random numbers
INIT - Removing 20 nodes
--
1.8.1.4
More information about the devel
mailing list