util/set: add the found param to search_or_add
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 7 Jan 2021 14:38:52 +0000 (09:38 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 14 Jan 2021 13:51:35 +0000 (13:51 +0000)
this brings parity with the internal api

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8450>

src/compiler/nir/nir_instr_set.c
src/util/set.c
src/util/set.h
src/util/tests/set/set_test.cpp

index dce7b2a..2d65250 100644 (file)
@@ -807,7 +807,7 @@ nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr)
    if (!instr_can_rewrite(instr))
       return false;
 
-   struct set_entry *e = _mesa_set_search_or_add(instr_set, instr);
+   struct set_entry *e = _mesa_set_search_or_add(instr_set, instr, NULL);
    nir_instr *match = (nir_instr *) e->key;
    if (match != instr) {
       nir_ssa_def *def = nir_instr_get_dest_ssa_def(instr);
index f071aca..fe945e7 100644 (file)
@@ -510,15 +510,15 @@ _mesa_set_search_and_add_pre_hashed(struct set *set, uint32_t hash,
 }
 
 struct set_entry *
-_mesa_set_search_or_add(struct set *set, const void *key)
+_mesa_set_search_or_add(struct set *set, const void *key, bool *found)
 {
    assert(set->key_hash_function);
-   return set_search_or_add(set, set->key_hash_function(key), key, NULL);
+   return set_search_or_add(set, set->key_hash_function(key), key, found);
 }
 
 struct set_entry *
 _mesa_set_search_or_add_pre_hashed(struct set *set, uint32_t hash,
-                                   const void *key)
+                                   const void *key, bool *found)
 {
    assert(set->key_hash_function == NULL ||
           hash == set->key_hash_function(key));
index 1836864..cabff35 100644 (file)
@@ -81,10 +81,10 @@ struct set_entry *
 _mesa_set_add_pre_hashed(struct set *set, uint32_t hash, const void *key);
 
 struct set_entry *
-_mesa_set_search_or_add(struct set *set, const void *key);
+_mesa_set_search_or_add(struct set *set, const void *key, bool *found);
 struct set_entry *
 _mesa_set_search_or_add_pre_hashed(struct set *set, uint32_t hash,
-                                   const void *key);
+                                   const void *key, bool *found);
 
 struct set_entry *
 _mesa_set_search(const struct set *set, const void *key);
index 6eda08d..6b9c993 100644 (file)
@@ -143,12 +143,16 @@ TEST(set, search_or_add)
    _mesa_set_add(s, &b);
    EXPECT_EQ(s->entries, 2);
 
-   struct set_entry *entry = _mesa_set_search_or_add(s, &c);
+   bool found = false;
+   struct set_entry *entry = _mesa_set_search_or_add(s, &c, &found);
    EXPECT_EQ(entry->key, (void *)&b);
+   EXPECT_EQ(found, true);
    EXPECT_EQ(s->entries, 2);
 
-   struct set_entry *entry3 = _mesa_set_search_or_add(s, &d);
+   found = false;
+   struct set_entry *entry3 = _mesa_set_search_or_add(s, &d, &found);
    EXPECT_EQ(entry3->key, &d);
+   EXPECT_EQ(found, false);
    EXPECT_EQ(s->entries, 3);
 
    _mesa_set_destroy(s, NULL);