mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
ghash: Clarify that g_hash_table_add() always consumes the key
Even if the key already exists in the table, `g_hash_table_add()` will call the hash table’s key free func on the old key and will then replace the old key with the newly-passed-in key. So `key` is always `(transfer full)`. In particular, `key` should never need to be freed by the caller if `g_hash_table_add()` returns `FALSE`. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
b6b18f0190
commit
b52bb75327
@ -1651,12 +1651,16 @@ g_hash_table_replace (GHashTable *hash_table,
|
||||
/**
|
||||
* g_hash_table_add:
|
||||
* @hash_table: a #GHashTable
|
||||
* @key: a key to insert
|
||||
* @key: (transfer full): a key to insert
|
||||
*
|
||||
* This is a convenience function for using a #GHashTable as a set. It
|
||||
* is equivalent to calling g_hash_table_replace() with @key as both the
|
||||
* key and the value.
|
||||
*
|
||||
* In particular, this means that if @key already exists in the hash table, then
|
||||
* the old copy of @key in the hash table is freed and @key replaces it in the
|
||||
* table.
|
||||
*
|
||||
* When a hash table only ever contains keys that have themselves as the
|
||||
* corresponding value it is able to be stored more efficiently. See
|
||||
* the discussion in the section description.
|
||||
|
Loading…
Reference in New Issue
Block a user