mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 20:00:32 +01:00
glib-compat: add compatibility function for g_hash_table_insert() and g_hash_table_add()
They have a different name, because we don't want to do the extra work unless explicitly requested.
This commit is contained in:
parent
df27e6d5fd
commit
261dff429e
1 changed files with 29 additions and 0 deletions
|
|
@ -185,6 +185,35 @@ nm_g_hash_table_replace (GHashTable *hash, gpointer key, gpointer value)
|
|||
#endif
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
nm_g_hash_table_insert (GHashTable *hash, gpointer key, gpointer value)
|
||||
{
|
||||
/* glib 2.40 added a return value indicating whether the key already existed
|
||||
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
|
||||
#if GLIB_CHECK_VERSION(2, 40, 0)
|
||||
return g_hash_table_insert (hash, key, value);
|
||||
#else
|
||||
gboolean contained = g_hash_table_contains (hash, key);
|
||||
|
||||
g_hash_table_insert (hash, key, value);
|
||||
return !contained;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
nm_g_hash_table_add (GHashTable *hash, gpointer key)
|
||||
{
|
||||
/* glib 2.40 added a return value indicating whether the key already existed
|
||||
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
|
||||
#if GLIB_CHECK_VERSION(2, 40, 0)
|
||||
return g_hash_table_add (hash, key);
|
||||
#else
|
||||
gboolean contained = g_hash_table_contains (hash, key);
|
||||
|
||||
g_hash_table_add (hash, key);
|
||||
return !contained;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 40, 0) || defined (NM_GLIB_COMPAT_H_TEST)
|
||||
static inline void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue