X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=libiberty%2Fsplay-tree.c;h=7c8973c63c8fead8e1363f4f42a5f686fb16ac8c;hb=f1cee837665a932d3d747597d8512cd0d3650478;hp=21d23c38dfc01d5a93846cafb572b94de8597539;hpb=d7167c671da0323daf31a8e07945c57c25f858d2;p=binutils-gdb.git diff --git a/libiberty/splay-tree.c b/libiberty/splay-tree.c index 21d23c38dfc..7c8973c63c8 100644 --- a/libiberty/splay-tree.c +++ b/libiberty/splay-tree.c @@ -1,5 +1,5 @@ /* A splay-tree datatype. - Copyright (C) 1998-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2021 Free Software Foundation, Inc. Contributed by Mark Mitchell (mark@markmitchell.com). This file is part of GNU CC. @@ -318,7 +318,11 @@ different types need to be allocated with different allocators. The splay tree will use @var{compare_fn} to compare nodes, @var{delete_key_fn} to deallocate keys, and @var{delete_value_fn} to -deallocate values. +deallocate values. Keys and values will be deallocated when the +tree is deleted using splay_tree_delete or when a node is removed +using splay_tree_remove. splay_tree_insert will release the previously +inserted key and value using @var{delete_key_fn} and @var{delete_value_fn} +if the inserted key is already found in the tree. @end deftypefn @@ -372,10 +376,13 @@ splay_tree_insert (splay_tree sp, splay_tree_key key, splay_tree_value value) if (sp->root && comparison == 0) { - /* If the root of the tree already has the indicated KEY, just - replace the value with VALUE. */ + /* If the root of the tree already has the indicated KEY, delete + the old key and old value, and replace them with KEY and VALUE. */ + if (sp->delete_key) + (*sp->delete_key) (sp->root->key); if (sp->delete_value) (*sp->delete_value)(sp->root->value); + sp->root->key = key; sp->root->value = value; } else