ghash: comment g_hash_table_steal_extended() about not destroying key/value

The previous text was technically correct, but not very clear what
happens with the ownership of the key/value if it was not returned.
Elaborate on the fact, that the key/value is never destroyed, even if
not requested by the user.

I intuitively expected the function to behave differently, that is, to
destroy the key/value if (and only if) it was not returned. That is,
when the function does not return a pointer, then it would destroy it.
That would seem more consistent to me, where ownership is either
transferred to the caller, or the resource destroyed during the steal.

On the other hand, the existing behaviors is:

- is consistent with g_hash_table_steal() and never destroys key/value.
- behaves the same, regardless whether the key/value was returned.

So the existing behavior may be better.

Just elaborate on that detail in the doc.
This commit is contained in:
Thomas Haller 2022-10-14 12:49:21 +02:00 committed by Philip Withnall
parent 52917f57ca
commit 4a709d0b46

View File

@ -1834,7 +1834,9 @@ g_hash_table_steal (GHashTable *hash_table,
*
* If found, the stolen key and value are removed from the hash table without
* calling the key and value destroy functions, and ownership is transferred to
* the caller of this method; as with g_hash_table_steal().
* the caller of this method, as with g_hash_table_steal(). That is the case
* regardless whether @stolen_key or @stolen_value output parameters are
* requested.
*
* You can pass %NULL for @lookup_key, provided the hash and equal functions
* of @hash_table are %NULL-safe.