]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
hash-table.h (remove_elt_with_hash): Return if slot is NULL rather than if is_empty...
authorJason Merrill <jason@redhat.com>
Thu, 14 Mar 2019 22:47:01 +0000 (18:47 -0400)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 14 Mar 2019 22:47:01 +0000 (23:47 +0100)
* hash-table.h (remove_elt_with_hash): Return if slot is NULL rather
than if is_empty (*slot).
* hash-set-tests.c (test_set_of_strings): Add tests for addition of
existing elt and for elt removal.
* hash-map-tests.c (test_map_of_strings_to_int): Add test for removal
of already removed elt.

* hashtab.c (htab_remove_elt_with_hash): Return if slot is NULL rather
than if *slot is HTAB_EMPTY_ENTRY.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r269695

gcc/ChangeLog
gcc/hash-map-tests.c
gcc/hash-set-tests.c
gcc/hash-table.h
libiberty/ChangeLog
libiberty/hashtab.c

index 4890c75c94b6270de9724f0e16615378f18b6246..394271f8bc269713b1d2e6393119e2154f19d598 100644 (file)
@@ -1,3 +1,13 @@
+2019-03-14  Jason Merrill  <jason@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       * hash-table.h (remove_elt_with_hash): Return if slot is NULL rather
+       than if is_empty (*slot).
+       * hash-set-tests.c (test_set_of_strings): Add tests for addition of
+       existing elt and for elt removal.
+       * hash-map-tests.c (test_map_of_strings_to_int): Add test for removal
+       of already removed elt.
+
 2019-03-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/89650
index 2137464e69378d6666a6703c16991310e4dc4100..acbfdb9e9ab2b64ea86f98426aabb3faaa867ed8 100644 (file)
@@ -78,6 +78,10 @@ test_map_of_strings_to_int ()
   ASSERT_EQ (5, m.elements ());
   ASSERT_EQ (NULL, m.get (eric));
 
+  m.remove (eric);
+  ASSERT_EQ (5, m.elements ());
+  ASSERT_EQ (NULL, m.get (eric));
+
   /* A plain char * key is hashed based on its value (address), rather
      than the string it points to.  */
   char *another_ant = static_cast <char *> (xcalloc (4, 1));
index 5ca1e4eea8c60bef30752f21e7582eb699676006..f75d41aed39d26dd223445774a52cc0b6854eea8 100644 (file)
@@ -48,11 +48,26 @@ test_set_of_strings ()
   ASSERT_EQ (false, s.add (red));
   ASSERT_EQ (false, s.add (green));
   ASSERT_EQ (false, s.add (blue));
+  ASSERT_EQ (true, s.add (green));
 
   /* Verify that the values are now within the set.  */
   ASSERT_EQ (true, s.contains (red));
   ASSERT_EQ (true, s.contains (green));
   ASSERT_EQ (true, s.contains (blue));
+  ASSERT_EQ (3, s.elements ());
+
+  /* Test removal.  */
+  s.remove (red);
+  ASSERT_EQ (false, s.contains (red));
+  ASSERT_EQ (true, s.contains (green));
+  ASSERT_EQ (true, s.contains (blue));
+  ASSERT_EQ (2, s.elements ());
+
+  s.remove (red);
+  ASSERT_EQ (false, s.contains (red));
+  ASSERT_EQ (true, s.contains (green));
+  ASSERT_EQ (true, s.contains (blue));
+  ASSERT_EQ (2, s.elements ());
 }
 
 /* Run all of the selftests within this file.  */
index 1fd36946a5351e378abb5e3e33297b43ccbfe0c0..9e09fa487f8ff23757e880e44583178375ba033a 100644 (file)
@@ -940,7 +940,7 @@ hash_table<Descriptor, Allocator>
 ::remove_elt_with_hash (const compare_type &comparable, hashval_t hash)
 {
   value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT);
-  if (is_empty (*slot))
+  if (slot == NULL)
     return;
 
   Descriptor::remove (*slot);
index f632558992779204037c69df62ca9aa60e25402a..cc44e4213d139479b13229d858af634bcbf0ddd5 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-14  Jason Merrill  <jason@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       * hashtab.c (htab_remove_elt_with_hash): Return if slot is NULL rather
+       than if *slot is HTAB_EMPTY_ENTRY.
+
 2019-02-11  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
        * splay-tree.c (splay_tree_insert): Also release old KEY in case
index 880c8787716520d8c80583ceb9c678a8b8dde065..9f917c3571d96a6ebd1e472f85bb85787f715a6c 100644 (file)
@@ -725,7 +725,7 @@ htab_remove_elt_with_hash (htab_t htab, PTR element, hashval_t hash)
   PTR *slot;
 
   slot = htab_find_slot_with_hash (htab, element, hash, NO_INSERT);
-  if (*slot == HTAB_EMPTY_ENTRY)
+  if (slot == NULL)
     return;
 
   if (htab->del_f)