Bug 1365460 - Remove unused macros from rb.h. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 17 May 2017 11:23:10 +0900
changeset 580746 de912210fc3a660d9eaa72277ff32b449f2b5e4b
parent 580745 d4687badde12c0a092199c1f016906aebea1e5df
child 580747 4f71522f701b32ee1ec82e2babf6a7386e5c6db8
push id59654
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 May 2017 22:44:22 +0000
reviewersnjn
bugs1365460
milestone55.0a1
Bug 1365460 - Remove unused macros from rb.h. r?njn
memory/mozjemalloc/rb.h
--- a/memory/mozjemalloc/rb.h
+++ b/memory/mozjemalloc/rb.h
@@ -67,21 +67,16 @@
  * comparison function, which makes it possible to write comparison functions
  * that treat the first argument specially.
  *
  ******************************************************************************/
 
 #ifndef RB_H_
 #define	RB_H_
 
-#if 0
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libc/stdlib/rb.h 178995 2008-05-14 18:33:13Z jasone $");
-#endif
-
 /* Node structure. */
 #define	rb_node(a_type)							\
 struct {								\
     a_type *rbn_left;							\
     a_type *rbn_right_red;						\
 }
 
 /* Root structure. */
@@ -276,33 +271,16 @@ struct {								\
 	}								\
     }									\
 } while (0)
 
 /*
  * Find a match if it exists.  Otherwise, find the previous lesser node, if one
  * exists.
  */
-#define	rb_psearch(a_type, a_field, a_cmp, a_tree, a_key, r_node) do {	\
-    a_type *rbp_ps_t = (a_tree)->rbt_root;				\
-    (r_node) = NULL;							\
-    while (rbp_ps_t != &(a_tree)->rbt_nil) {				\
-	int rbp_ps_cmp = (a_cmp)((a_key), rbp_ps_t);			\
-	if (rbp_ps_cmp < 0) {						\
-	    rbp_ps_t = rbp_left_get(a_type, a_field, rbp_ps_t);		\
-	} else if (rbp_ps_cmp > 0) {					\
-	    (r_node) = rbp_ps_t;					\
-	    rbp_ps_t = rbp_right_get(a_type, a_field, rbp_ps_t);	\
-	} else {							\
-	    (r_node) = rbp_ps_t;					\
-	    break;							\
-	}								\
-    }									\
-} while (0)
-
 #define	rbp_rotate_left(a_type, a_field, a_node, r_node) do {		\
     (r_node) = rbp_right_get(a_type, a_field, (a_node));		\
     rbp_right_set(a_type, a_field, (a_node),				\
       rbp_left_get(a_type, a_field, (r_node)));				\
     rbp_left_set(a_type, a_field, (r_node), (a_node));			\
 } while (0)
 
 #define	rbp_rotate_right(a_type, a_field, a_node, r_node) do {		\
@@ -726,22 +704,16 @@ a_prefix##search(a_tree_type *tree, a_ty
     return (ret);							\
 }									\
 a_attr a_type *								\
 a_prefix##nsearch(a_tree_type *tree, a_type *key) {			\
     a_type *ret;							\
     rb_nsearch(a_type, a_field, a_cmp, tree, key, ret);			\
     return (ret);							\
 }									\
-a_attr a_type *								\
-a_prefix##psearch(a_tree_type *tree, a_type *key) {			\
-    a_type *ret;							\
-    rb_psearch(a_type, a_field, a_cmp, tree, key, ret);			\
-    return (ret);							\
-}									\
 a_attr void								\
 a_prefix##insert(a_tree_type *tree, a_type *node) {			\
     rb_insert(a_type, a_field, a_cmp, tree, node);			\
 }									\
 a_attr void								\
 a_prefix##remove(a_tree_type *tree, a_type *node) {			\
     rb_remove(a_type, a_field, a_cmp, tree, node);			\
 }
@@ -758,17 +730,16 @@ a_prefix##remove(a_tree_type *tree, a_ty
  *
  *   {
  *       a_type *node, *tnode;
  *
  *       rb_foreach_begin(a_type, a_field, a_tree, node) {
  *           ...
  *           rb_next(a_type, a_field, a_cmp, a_tree, node, tnode);
  *           rb_remove(a_type, a_field, a_cmp, a_tree, node);
- *           rb_foreach_next(a_type, a_field, a_cmp, a_tree, tnode);
  *           ...
  *       } rb_foreach_end(a_type, a_field, a_tree, node)
  *   }
  *
  * Note that this idiom is not advised if every iteration modifies the tree,
  * since in that case there is no algorithmic complexity improvement over a
  * series of rb_{next,prev}() calls, thus making the setup overhead wasted
  * effort.
@@ -788,29 +759,22 @@ a_prefix##remove(a_tree_type *tree, a_ty
     *
     *   (3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1)))
     *
     * This works out to a maximum depth of 87 and 180 for 32- and 64-bit
     * systems, respectively (approximatly 348 and 1440 bytes, respectively).
     */
 #  define rbp_compute_f_height(a_type, a_field, a_tree)
 #  define rbp_f_height	(3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1)))
-#  define rbp_compute_fr_height(a_type, a_field, a_tree)
-#  define rbp_fr_height	(3 * ((SIZEOF_PTR<<3) - (SIZEOF_PTR_2POW+1)))
 #else
 #  define rbp_compute_f_height(a_type, a_field, a_tree)			\
     /* Compute the maximum possible tree depth (3X the black height). */\
     unsigned rbp_f_height;						\
     rbp_black_height(a_type, a_field, a_tree, rbp_f_height);		\
     rbp_f_height *= 3;
-#  define rbp_compute_fr_height(a_type, a_field, a_tree)		\
-    /* Compute the maximum possible tree depth (3X the black height). */\
-    unsigned rbp_fr_height;						\
-    rbp_black_height(a_type, a_field, a_tree, rbp_fr_height);		\
-    rbp_fr_height *= 3;
 #endif
 
 #define	rb_foreach_begin(a_type, a_field, a_tree, a_var) {		\
     rbp_compute_f_height(a_type, a_field, a_tree)			\
     {									\
 	/* Initialize the path to contain the left spine.             */\
 	a_type *rbp_f_path[rbp_f_height];				\
 	a_type *rbp_f_node;						\
@@ -824,45 +788,16 @@ a_prefix##remove(a_tree_type *tree, a_ty
 		rbp_f_path[rbp_f_depth] = rbp_f_node;			\
 		rbp_f_depth++;						\
 	    }								\
 	}								\
 	/* While the path is non-empty, iterate.                      */\
 	while (rbp_f_depth > 0) {					\
 	    (a_var) = rbp_f_path[rbp_f_depth-1];
 
-/* Only use if modifying the tree during iteration. */
-#define	rb_foreach_next(a_type, a_field, a_cmp, a_tree, a_node)		\
-	    /* Re-initialize the path to contain the path to a_node.  */\
-	    rbp_f_depth = 0;						\
-	    if (a_node != NULL) {					\
-		if ((a_tree)->rbt_root != &(a_tree)->rbt_nil) {		\
-		    rbp_f_path[rbp_f_depth] = (a_tree)->rbt_root;	\
-		    rbp_f_depth++;					\
-		    rbp_f_node = rbp_f_path[0];				\
-		    while (true) {					\
-			int rbp_f_cmp = (a_cmp)((a_node),		\
-			  rbp_f_path[rbp_f_depth-1]);			\
-			if (rbp_f_cmp < 0) {				\
-			    rbp_f_node = rbp_left_get(a_type, a_field,	\
-			      rbp_f_path[rbp_f_depth-1]);		\
-			} else if (rbp_f_cmp > 0) {			\
-			    rbp_f_node = rbp_right_get(a_type, a_field,	\
-			      rbp_f_path[rbp_f_depth-1]);		\
-			} else {					\
-			    break;					\
-			}						\
-			assert(rbp_f_node != &(a_tree)->rbt_nil);	\
-			rbp_f_path[rbp_f_depth] = rbp_f_node;		\
-			rbp_f_depth++;					\
-		    }							\
-		}							\
-	    }								\
-	    rbp_f_synced = true;
-
 #define	rb_foreach_end(a_type, a_field, a_tree, a_var)			\
 	    if (rbp_f_synced) {						\
 		rbp_f_synced = false;					\
 		continue;						\
 	    }								\
 	    /* Find the successor.                                    */\
 	    if ((rbp_f_node = rbp_right_get(a_type, a_field,		\
 	      rbp_f_path[rbp_f_depth-1])) != &(a_tree)->rbt_nil) {	\
@@ -886,97 +821,9 @@ a_prefix##remove(a_tree_type *tree, a_ty
 			break;						\
 		    }							\
 		}							\
 	    }								\
 	}								\
     }									\
 }
 
-#define	rb_foreach_reverse_begin(a_type, a_field, a_tree, a_var) {	\
-    rbp_compute_fr_height(a_type, a_field, a_tree)			\
-    {									\
-	/* Initialize the path to contain the right spine.            */\
-	a_type *rbp_fr_path[rbp_fr_height];				\
-	a_type *rbp_fr_node;						\
-	bool rbp_fr_synced = false;					\
-	unsigned rbp_fr_depth = 0;					\
-	if ((a_tree)->rbt_root != &(a_tree)->rbt_nil) {			\
-	    rbp_fr_path[rbp_fr_depth] = (a_tree)->rbt_root;		\
-	    rbp_fr_depth++;						\
-	    while ((rbp_fr_node = rbp_right_get(a_type, a_field,	\
-	      rbp_fr_path[rbp_fr_depth-1])) != &(a_tree)->rbt_nil) {	\
-		rbp_fr_path[rbp_fr_depth] = rbp_fr_node;		\
-		rbp_fr_depth++;						\
-	    }								\
-	}								\
-	/* While the path is non-empty, iterate.                      */\
-	while (rbp_fr_depth > 0) {					\
-	    (a_var) = rbp_fr_path[rbp_fr_depth-1];
-
-/* Only use if modifying the tree during iteration. */
-#define	rb_foreach_reverse_prev(a_type, a_field, a_cmp, a_tree, a_node)	\
-	    /* Re-initialize the path to contain the path to a_node.  */\
-	    rbp_fr_depth = 0;						\
-	    if (a_node != NULL) {					\
-		if ((a_tree)->rbt_root != &(a_tree)->rbt_nil) {		\
-		    rbp_fr_path[rbp_fr_depth] = (a_tree)->rbt_root;	\
-		    rbp_fr_depth++;					\
-		    rbp_fr_node = rbp_fr_path[0];			\
-		    while (true) {					\
-			int rbp_fr_cmp = (a_cmp)((a_node),		\
-			  rbp_fr_path[rbp_fr_depth-1]);			\
-			if (rbp_fr_cmp < 0) {				\
-			    rbp_fr_node = rbp_left_get(a_type, a_field,	\
-			      rbp_fr_path[rbp_fr_depth-1]);		\
-			} else if (rbp_fr_cmp > 0) {			\
-			    rbp_fr_node = rbp_right_get(a_type, a_field,\
-			      rbp_fr_path[rbp_fr_depth-1]);		\
-			} else {					\
-			    break;					\
-			}						\
-			assert(rbp_fr_node != &(a_tree)->rbt_nil);	\
-			rbp_fr_path[rbp_fr_depth] = rbp_fr_node;	\
-			rbp_fr_depth++;					\
-		    }							\
-		}							\
-	    }								\
-	    rbp_fr_synced = true;
-
-#define	rb_foreach_reverse_end(a_type, a_field, a_tree, a_var)		\
-	    if (rbp_fr_synced) {					\
-		rbp_fr_synced = false;					\
-		continue;						\
-	    }								\
-	    if (rbp_fr_depth == 0) {					\
-		/* rb_foreach_reverse_sync() was called with a NULL   */\
-		/* a_node.                                            */\
-		break;							\
-	    }								\
-	    /* Find the predecessor.                                  */\
-	    if ((rbp_fr_node = rbp_left_get(a_type, a_field,		\
-	      rbp_fr_path[rbp_fr_depth-1])) != &(a_tree)->rbt_nil) {	\
-	        /* The predecessor is the right-most node in the left */\
-		/* subtree.                                           */\
-		rbp_fr_path[rbp_fr_depth] = rbp_fr_node;		\
-		rbp_fr_depth++;						\
-		while ((rbp_fr_node = rbp_right_get(a_type, a_field,	\
-		  rbp_fr_path[rbp_fr_depth-1])) != &(a_tree)->rbt_nil) {\
-		    rbp_fr_path[rbp_fr_depth] = rbp_fr_node;		\
-		    rbp_fr_depth++;					\
-		}							\
-	    } else {							\
-		/* The predecessor is above the current node.  Unwind */\
-		/* until a right-leaning edge is removed from the     */\
-		/* path, or the path is empty.                        */\
-		for (rbp_fr_depth--; rbp_fr_depth > 0; rbp_fr_depth--) {\
-		    if (rbp_right_get(a_type, a_field,			\
-		      rbp_fr_path[rbp_fr_depth-1])			\
-		      == rbp_fr_path[rbp_fr_depth]) {			\
-			break;						\
-		    }							\
-		}							\
-	    }								\
-	}								\
-    }									\
-}
-
 #endif /* RB_H_ */