[PATCH 2/3] rbtree: Remove superfluous NULL pointer checks

Joel Sherrill joel.sherrill at oarcorp.com
Mon Jul 21 16:59:41 UTC 2014


One comment inline.

On 7/21/2014 11:31 AM, Sebastian Huber wrote:
> ---
>  cpukit/score/include/rtems/score/rbtree.h |  7 +++----
>  cpukit/score/src/rbtree.c                 |  3 ---
>  cpukit/score/src/rbtreeextract.c          | 10 ----------
>  cpukit/score/src/rbtreeinsert.c           |  3 ---
>  testsuites/sptests/sprbtree01/init.c      |  3 ---
>  5 files changed, 3 insertions(+), 23 deletions(-)
>
> diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
> index a219a6e..aa7b86e 100644
> --- a/cpukit/score/include/rtems/score/rbtree.h
> +++ b/cpukit/score/include/rtems/score/rbtree.h
> @@ -229,10 +229,9 @@ RBTree_Node *_RBTree_Find(
>   * @param[in] is_unique If true, then reject nodes with a duplicate key, else
>   *   otherwise.
>   *
> - *  @retval 0 Successfully inserted.
> - *  @retval -1 NULL @a the_node.
> - *  @retval RBTree_Node* if one with equal value to @a the_node 's key exists
> - *          in an unique @a the_rbtree.
> + * @retval NULL Successfully inserted.
> + * @retval existing_node This is a unique insert and there exists a node with
> + *   an equal key in the tree already.
>   */
>  RBTree_Node *_RBTree_Insert(
>    RBTree_Control *the_rbtree,
> diff --git a/cpukit/score/src/rbtree.c b/cpukit/score/src/rbtree.c
> index 2138a81..064cc0c 100644
> --- a/cpukit/score/src/rbtree.c
> +++ b/cpukit/score/src/rbtree.c
> @@ -34,9 +34,6 @@ void _RBTree_Initialize(
>    size_t       count;
>    RBTree_Node *next;
>  
> -  /* TODO: Error message? */
> -  if ( !the_rbtree ) return;
> -
>    /* could do sanity checks here */
>    _RBTree_Initialize_empty( the_rbtree );
>  
> diff --git a/cpukit/score/src/rbtreeextract.c b/cpukit/score/src/rbtreeextract.c
> index 2638f63..7775b2f 100644
> --- a/cpukit/score/src/rbtreeextract.c
> +++ b/cpukit/score/src/rbtreeextract.c
> @@ -11,7 +11,6 @@
>  #endif
>  
>  #include <rtems/score/rbtreeimpl.h>
> -#include <rtems/score/isr.h>
>  
>  /** @brief  Validate and fix-up tree properties after deleting a node
>   *
> @@ -90,13 +89,6 @@ static void _RBTree_Extract_validate( RBTree_Node *the_node )
>      the_node->color = RBT_BLACK;
>  }
>  
> -/** @brief Extract a Node (unprotected)
> - *
> - *  This routine extracts (removes) @a the_node from @a the_rbtree.
> - *
> - *  @note It does NOT disable interrupts to ensure the atomicity
> - *        of the extract operation.
> - */

Is it assumed that all RBTree  operations are unprotected?

If so, should this be in the Doxygen group description. If not, then this
comment is meaningful and should be in the .h.
>  void _RBTree_Extract(
>    RBTree_Control *the_rbtree,
>    RBTree_Node    *the_node
> @@ -106,8 +98,6 @@ void _RBTree_Extract(
>    RBTree_Color     victim_color;
>    RBTree_Direction dir;
>  
> -  if ( !the_node ) return;
> -
>    /* check if min needs to be updated */
>    if ( the_node == the_rbtree->first[ RBT_LEFT ] ) {
>      RBTree_Node *next;
> diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
> index 369ef26..b31c8e7 100644
> --- a/cpukit/score/src/rbtreeinsert.c
> +++ b/cpukit/score/src/rbtreeinsert.c
> @@ -11,7 +11,6 @@
>  #endif
>  
>  #include <rtems/score/rbtreeimpl.h>
> -#include <rtems/score/isr.h>
>  
>  /** @brief Validate and fix-up tree properties for a new insert/colored node
>   *
> @@ -67,8 +66,6 @@ RBTree_Node *_RBTree_Insert(
>    bool            is_unique
>  )
>  {
> -  if ( !the_node ) return (RBTree_Node *) -1;
> -
>    RBTree_Node *iter_node = the_rbtree->root;
>  
>    if ( !iter_node ) { /* special case: first node inserted */
> diff --git a/testsuites/sptests/sprbtree01/init.c b/testsuites/sptests/sprbtree01/init.c
> index acf7f68..ca79095 100644
> --- a/testsuites/sptests/sprbtree01/init.c
> +++ b/testsuites/sptests/sprbtree01/init.c
> @@ -149,9 +149,6 @@ rtems_task Init(
>    rb_insert_unique( &rbtree1, &node1.Node );
>    rb_insert_unique( &rbtree1, &node2.Node );
>  
> -  p = rb_insert_unique( &rbtree1, NULL );
> -  if (p != (void *)(-1))
> -    puts( "INIT - FAILED NULL NODE INSERT" );
>  
>    _RBTree_Rotate(NULL, RBT_LEFT);
>    i = (node1.Node.parent == &node2.Node);

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the devel mailing list