]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Remove dead code from AVL tree
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 6 Oct 2017 02:28:00 +0000 (19:28 -0700)
committerGitHub <noreply@github.com>
Fri, 6 Oct 2017 02:28:00 +0000 (19:28 -0700)
The avl_update_* functions are never used by ZFS and are therefore
being removed.  They're barely even used in Illumos.  Additionally,
simplify avl_add() by using a VERIFY which produces exactly the same
behavior under Linux.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #6716

include/sys/avl.h
module/avl/avl.c

index ba51e2a790f40799d81b026ceebf4988b8603e5d..206b539fab54a0428f00e5fca26626a53133e1fd 100644 (file)
@@ -259,17 +259,6 @@ extern void avl_add(avl_tree_t *tree, void *node);
  */
 extern void avl_remove(avl_tree_t *tree, void *node);
 
-/*
- * Reinsert a node only if its order has changed relative to its nearest
- * neighbors. To optimize performance avl_update_lt() checks only the previous
- * node and avl_update_gt() checks only the next node. Use avl_update_lt() and
- * avl_update_gt() only if you know the direction in which the order of the
- * node may change.
- */
-extern boolean_t avl_update(avl_tree_t *, void *);
-extern boolean_t avl_update_lt(avl_tree_t *, void *);
-extern boolean_t avl_update_gt(avl_tree_t *, void *);
-
 /*
  * Swaps the contents of the two trees.
  */
index 7a79f3785f91dd81771d7bb5a6f983784c52429d..f024cdf61cb6ce7093820da751045b1bdb1daade 100644 (file)
@@ -626,25 +626,16 @@ avl_insert_here(
 }
 
 /*
- * Add a new node to an AVL tree.
+ * Add a new node to an AVL tree.  Strictly enforce that no duplicates can
+ * be added to the tree with a VERIFY which is enabled for non-DEBUG builds.
  */
 void
 avl_add(avl_tree_t *tree, void *new_node)
 {
        avl_index_t where = 0;
 
-       /*
-        * This is unfortunate.  We want to call panic() here, even for
-        * non-DEBUG kernels.  In userland, however, we can't depend on anything
-        * in libc or else the rtld build process gets confused.  So, all we can
-        * do in userland is resort to a normal ASSERT().
-        */
-       if (avl_find(tree, new_node, &where) != NULL)
-#ifdef _KERNEL
-               panic("avl_find() succeeded inside avl_add()");
-#else
-               ASSERT(0);
-#endif
+       VERIFY(avl_find(tree, new_node, &where) == NULL);
+
        avl_insert(tree, new_node, where);
 }
 
@@ -817,64 +808,6 @@ avl_remove(avl_tree_t *tree, void *data)
        } while (parent != NULL);
 }
 
-#define        AVL_REINSERT(tree, obj)         \
-       avl_remove((tree), (obj));      \
-       avl_add((tree), (obj))
-
-boolean_t
-avl_update_lt(avl_tree_t *t, void *obj)
-{
-       void *neighbor;
-
-       ASSERT(((neighbor = AVL_NEXT(t, obj)) == NULL) ||
-           (t->avl_compar(obj, neighbor) <= 0));
-
-       neighbor = AVL_PREV(t, obj);
-       if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) < 0)) {
-               AVL_REINSERT(t, obj);
-               return (B_TRUE);
-       }
-
-       return (B_FALSE);
-}
-
-boolean_t
-avl_update_gt(avl_tree_t *t, void *obj)
-{
-       void *neighbor;
-
-       ASSERT(((neighbor = AVL_PREV(t, obj)) == NULL) ||
-           (t->avl_compar(obj, neighbor) >= 0));
-
-       neighbor = AVL_NEXT(t, obj);
-       if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) > 0)) {
-               AVL_REINSERT(t, obj);
-               return (B_TRUE);
-       }
-
-       return (B_FALSE);
-}
-
-boolean_t
-avl_update(avl_tree_t *t, void *obj)
-{
-       void *neighbor;
-
-       neighbor = AVL_PREV(t, obj);
-       if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) < 0)) {
-               AVL_REINSERT(t, obj);
-               return (B_TRUE);
-       }
-
-       neighbor = AVL_NEXT(t, obj);
-       if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) > 0)) {
-               AVL_REINSERT(t, obj);
-               return (B_TRUE);
-       }
-
-       return (B_FALSE);
-}
-
 void
 avl_swap(avl_tree_t *tree1, avl_tree_t *tree2)
 {